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

Format

R6Class object inheriting from Task/TaskSupervised.

Usage

Inherits from Task/TaskSupervised.

# Construction
t = TaskClassif$new(id, backend, target, positive = NULL)
    # Members
t$all_classes
t$class_n
t$class_names
t$negative
t$positive

Arguments

  • positive (character(1)): Name of the "positive" class, only required for binary classification problems.

Details

  • $all_classes returns all class labels for the target column in the DataBackend. In contrast to $class_names, this is not restricted to the currently active rows.

  • $class_n returns the number of class labels of the rows which role == "use".

  • $class_names returns all class labels of the rows which role == "use".

  • $task_type is "classif".

See also

Examples

b = as_data_backend(iris) task = TaskClassif$new("iris", backend = b, target = "Species") task$task_type
#> [1] "classif"
task$formula
#> Species ~ Petal.Length + Petal.Width + Sepal.Length + Sepal.Width #> NULL
task$truth()
#> [1] setosa setosa setosa setosa setosa setosa #> [7] setosa setosa setosa setosa setosa setosa #> [13] setosa setosa setosa setosa setosa setosa #> [19] setosa setosa setosa setosa setosa setosa #> [25] setosa setosa setosa setosa setosa setosa #> [31] setosa setosa setosa setosa setosa setosa #> [37] setosa setosa setosa setosa setosa setosa #> [43] setosa setosa setosa setosa setosa setosa #> [49] setosa setosa versicolor versicolor versicolor versicolor #> [55] versicolor versicolor versicolor versicolor versicolor versicolor #> [61] versicolor versicolor versicolor versicolor versicolor versicolor #> [67] versicolor versicolor versicolor versicolor versicolor versicolor #> [73] versicolor versicolor versicolor versicolor versicolor versicolor #> [79] versicolor versicolor versicolor versicolor versicolor versicolor #> [85] versicolor versicolor versicolor versicolor versicolor versicolor #> [91] versicolor versicolor versicolor versicolor versicolor versicolor #> [97] versicolor versicolor versicolor versicolor virginica virginica #> [103] virginica virginica virginica virginica virginica virginica #> [109] virginica virginica virginica virginica virginica virginica #> [115] virginica virginica virginica virginica virginica virginica #> [121] virginica virginica virginica virginica virginica virginica #> [127] virginica virginica virginica virginica virginica virginica #> [133] virginica virginica virginica virginica virginica virginica #> [139] virginica virginica virginica virginica virginica virginica #> [145] virginica virginica virginica virginica virginica virginica #> Levels: setosa versicolor virginica
task$all_classes
#> [1] "setosa" "versicolor" "virginica"
task$class_names
#> [1] "setosa" "versicolor" "virginica"
data("Sonar", package = "mlbench") b = as_data_backend(Sonar) task = TaskClassif$new("sonar", backend = b, target = "Class", positive = "M") task$positive
#> [1] "M"
task$negative
#> [1] "R"