This task specializes Task and TaskSupervised for classification problems. The target column is assumed to be a factor. The task_type is set to "classif".

Predefined tasks are stored in mlr_tasks.

Format

R6::R6Class object inheriting from Task/TaskSupervised.

Construction

t = TaskClassif$new(id, backend, target, positive = NULL)

Fields

All methods from TaskSupervised, and additionally:

  • class_names :: character()
    Returns all class labels of the target column.

  • class_n :: integer(1)
    Returns the number of classes.

  • negative :: character(1)
    Stores the negative class for binary classification tasks, and NA for multiclass tasks.

  • positive :: character(1)
    Stores the positive class for binary classification tasks, and NA for multiclass tasks.

Methods

See TaskSupervised.

See also

Examples

data("Sonar", package = "mlbench") task = TaskClassif$new("sonar", backend = Sonar, target = "Class", positive = "M") task$task_type
#> [1] "classif"
task$formula()
#> Class ~ V1 + V10 + V11 + V12 + V13 + V14 + V15 + V16 + V17 + #> V18 + V19 + V2 + V20 + V21 + V22 + V23 + V24 + V25 + V26 + #> V27 + V28 + V29 + V3 + V30 + V31 + V32 + V33 + V34 + V35 + #> V36 + V37 + V38 + V39 + V4 + V40 + V41 + V42 + V43 + V44 + #> V45 + V46 + V47 + V48 + V49 + V5 + V50 + V51 + V52 + V53 + #> V54 + V55 + V56 + V57 + V58 + V59 + V6 + V60 + V7 + V8 + #> V9 #> NULL
task$truth()
#> [1] R R M M M M M M M M M M R M M M M M M M M M M R M M M M M M M M M M R M M #> [38] M M M M M M M M R M M M M M M M M M M R M M M M M M M M M M R M M M M M M #> [75] M M M M R M M M M M M M M M M R M M M M M M M M M M R M M M M M M M M M M #> [112] R R M M M M M M M M M R R R R R R R R R R R R R R R R R R R R R R R R R R #> [149] R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R #> [186] R R R R R R R R R R R R R R R R R R R R R M M #> Levels: M R
task$class_names
#> [1] "M" "R"
task$positive
#> [1] "M"
task$negative
#> [1] "R"
# possible properties: mlr_reflections$task_properties$classif
#> [1] "weights" "groups" "twoclass" "multiclass"