Convert object to a TaskClust or a list of TaskClust. This is a S3 generic, specialized for at least the following objects:
TaskClust: returns the object as-is, possibly cloned.
formula,data.frame(),matrix(), and mlr3::DataBackend: provides an alternative to the constructor of TaskClust.mlr3::TaskSupervised (e.g., mlr3::TaskClassif or mlr3::TaskRegr): converts the task to a TaskClust by dropping the target, analogous to
mlr3::convert_task().
Usage
as_task_clust(x, ...)
# S3 method for class 'TaskClust'
as_task_clust(x, clone = FALSE, ...)
# S3 method for class 'TaskSupervised'
as_task_clust(x, drop_levels = TRUE, ...)
# S3 method for class 'data.frame'
as_task_clust(x, id = deparse1(substitute(x)), label = NA_character_, ...)
# S3 method for class 'matrix'
as_task_clust(x, id = deparse1(substitute(x)), label = NA_character_, ...)
# S3 method for class 'DataBackend'
as_task_clust(x, id = deparse1(substitute(x)), label = NA_character_, ...)
# S3 method for class 'formula'
as_task_clust(
x,
data,
id = deparse1(substitute(data)),
label = NA_character_,
...
)
as_tasks_clust(x, ...)
# S3 method for class 'list'
as_tasks_clust(x, clone = FALSE, ...)
# S3 method for class 'TaskClust'
as_tasks_clust(x, clone = FALSE, ...)Arguments
- x
(any)
Object to convert.- ...
(any)
Additional arguments.- clone
(
logical(1))
IfTRUE, ensures that the returned object is not the same as the inputx.- drop_levels
(
logical(1))
IfTRUE, drops unused levels of factor columns, as inmlr3::convert_task().- id
(
character(1))
Id for the new task. Defaults to the (deparsed and substituted) name of the data argument.- label
(
character(1))
Label for the new instance.- data
(
data.frame())
Data frame containing all columns specified in formulax.
Examples
as_task_clust(datasets::USArrests)
#>
#> ── <TaskClust> (50x4) ──────────────────────────────────────────────────────────
#> • Target:
#> • Properties: -
#> • Features (4):
#> • int (2): Assault, UrbanPop
#> • dbl (2): Murder, Rape
# convert a classification task to a cluster task
as_task_clust(tsk("iris"))
#>
#> ── <TaskClust> (150x4): Iris Flowers ───────────────────────────────────────────
#> • Target:
#> • Properties: -
#> • Features (4):
#> • dbl (4): Petal.Length, Petal.Width, Sepal.Length, Sepal.Width
# turn any task generator into a cluster task generator
as_task_clust(tgen("moons")$generate(100))
#>
#> ── <TaskClust> (100x2) ─────────────────────────────────────────────────────────
#> • Target:
#> • Properties: -
#> • Features (2):
#> • dbl (2): x1, x2