Convert object to a TaskClassif. This is a S3 generic. mlr3 ships with methods for the following objects:
TaskClassif: returns the object as-is, possibly cloned.
formula,data.frame(),matrix(), and DataBackend: provides an alternative to the constructor of TaskClassif.TaskRegr: Calls
convert_task().
Note that the target column will be converted to a factor(), if possible.
Usage
as_task_classif(x, ...)
# S3 method for class 'TaskClassif'
as_task_classif(x, clone = FALSE, ...)
# S3 method for class 'data.frame'
as_task_classif(
  x,
  target,
  id = deparse1(substitute(x)),
  positive = NULL,
  label = NA_character_,
  ...
)
# S3 method for class 'matrix'
as_task_classif(
  x,
  target,
  id = deparse1(substitute(x)),
  label = NA_character_,
  ...
)
# S3 method for class 'DataBackend'
as_task_classif(
  x,
  target,
  id = deparse1(substitute(x)),
  positive = NULL,
  label = NA_character_,
  ...
)
# S3 method for class 'TaskRegr'
as_task_classif(
  x,
  target,
  drop_original_target = FALSE,
  drop_levels = TRUE,
  ...
)
# S3 method for class 'formula'
as_task_classif(
  x,
  data,
  id = deparse1(substitute(data)),
  positive = NULL,
  label = NA_character_,
  ...
)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.- target
 (
character(1))
Name of the target column.- id
 (
character(1))
Id for the new task. Defaults to the (deparsed and substituted) name of the data argument.- positive
 (
character(1))
Level of the positive class. See TaskClassif.- label
 (
character(1))
Label for the new instance.- drop_original_target
 (
logical(1))
IfFALSE(default), the original target is added as a feature. Otherwise the original target is dropped.- drop_levels
 (
logical(1))
IfTRUE(default), unused levels of the new target variable are dropped.- data
 (
data.frame())
Data frame containing all columns referenced in formulax.
Examples
as_task_classif(palmerpenguins::penguins, target = "species")
#> 
#> ── <TaskClassif> (344x8) ───────────────────────────────────────────────────────
#> • Target: species
#> • Target classes: Adelie (44%), Gentoo (36%), Chinstrap (20%)
#> • Properties: multiclass
#> • Features (7):
#>   • int (3): body_mass_g, flipper_length_mm, year
#>   • dbl (2): bill_depth_mm, bill_length_mm
#>   • fct (2): island, sex