This is the abstract base class for task objects like TaskClassif and TaskRegr. It extends Task with methods to handle a target columns.

Format

R6::R6Class object inheriting from Task.

Construction

t = TaskSupervised$new(id, task_type, backend, target)  • id :: character(1) Name of the task. • backend :: DataBackend Either a DataBackend, or any object which is convertible to a DataBackend with as_data_backend(). E.g., a data.frame() will be converted to a DataBackendDataTable. • task_type :: character(1) Set in the classes which inherit from this class. Must be an element of mlr_reflections$task_types.

• target :: character(1)
Name of the target column.

Fields

• backend :: DataBackend.

• col_info :: data.table::data.table()
Table with with 3 columns: Column names of DataBackend are stored in columnid. Column type holds the storage type of the variables, e.g. integer, numeric or character. Column levels keeps a list of possible levels for factor and character variables.

• col_roles :: named list()
Each column (feature) can have an arbitrary number of roles in the learning task:

• "target": Labels to predict.

• "feature": Regular feature.

• "order": Data returned by data() is ordered by this column (or these columns).

• "groups": During resampling, observations with the same value of the variable with role "groups" are marked as "belonging together". They will be exclusively assigned to be either in the training set or the test set for each resampling iteration. Only a single column may be marked as grouping column.

• "weights": Observation weights. Only a single column may be marked as weights. col_roles keeps track of the roles with a named list of vectors of feature names. To alter the roles, use t$set_col_role(). • row_roles :: named list() Each row (observation) can have an arbitrary number of roles in the learning task: • "use": Use in train / predict / resampling. • "validation": Hold the observations back unless explicitly requested. row_roles keeps track of the roles with a named list of vectors of feature names. To alter the role, use set_row_role(). • feature_names :: character() Returns all column names with role == "feature". • feature_types :: data.table::data.table() Returns a table with columns id and type where id are the column names of "active" features of the task and type is the storage type. • hash :: character(1) Hash (unique identifier) for this object. • id :: character(1) Stores the identifier of the Task. • measures :: list() of Measure Stores the measures to use for this task. • ncol :: integer(1) Returns the total number of cols with role "target" or "feature". • nrow :: integer(1) Return the total number of rows with role "use". • row_ids :: (integer() | character()) Returns the row ids of the DataBackend for observations with with role "use". • target_names :: character() Returns all column names with role "target". • task_type :: character(1) Stores the type of the Task. • properties :: character() Set of task properties. Possible properties are are stored in mlr_reflections$task_properties.

• groups :: data.table::data.table()
If the task has a designated column role "groups", table with two columns: "row_id" (integer() | character()) and the grouping variable group (vector()). Returns NULL if there are is no grouping column.

• weights :: data.table::data.table()
If the task has a designated column role "weights", table with two columns: "row_id" (integer() | character()) and the observation weights weight (numeric()). Returns NULL if there are is no weight column.

Methods

• truth(row_ids = NULL) :: data.table::data.table()
Table with true labels for specified row_ids. Defaults to all rows in use.

• data(rows = NULL, cols = NULL, data_format = NULL)
(integer() | character(), character(), character()) -> any
Returns a slice of the data from the DataBackend in the data format specified by data_format (depending on the DataBackend, but usually a data.table::data.table()). It is possible to provide multiple formats, the first format supported is selected.

Rows are subsetted to only contain observations with role "use". Columns are filtered to only contain features with roles "target" and "feature". If invalid rows or cols are specified, an exception is raised.

• formula(rhs = NULL)
character() -> formula
Constructs a stats::formula, e.g. [target] ~ [feature_1] + [feature_2] + ... + [feature_k], using the features provided in argument rhs (defaults to all active features).

• levels(cols = NULL)
character() -> named list()
Returns the distinct values of columns in cols for columns with storage type "character", "factor" or "ordered". Argument cols defaults to all such columns with role "target" or "feature".

Note that this function ignores the row roles, it returns all levels available in the DataBackend. To update the stored level information, e.g. after filtering a task, call $droplevels(). • missings(cols = NULL) character() -> named integer() Returns the number of missing values observations for each columns in cols. Argument cols defaults to all columns with role "target" or "feature". • head(n = 6) integer() -> data.table::data.table() Get the first n observations with role "use". • set_col_role(cols, new_roles, exclusive = TRUE) (character(), character(), logical(1)) -> self Adds the roles new_roles to columns referred to by cols. If exclusive is TRUE, the referenced columns will be removed from all other roles. • set_row_role(rows, new_roles, exclusive = TRUE) (character(), character(), logical(1)) -> self Adds the roles new_roles to rows referred to by rows. If exclusive is TRUE, the referenced rows will be removed from all other roles. • filter(rows) (integer() | character()) -> self Subsets the task, reducing it to only keep the rows specified. See the section on task mutators for more information. • select(cols) character() -> self Subsets the task, reducing it to only keep the columns specified. See the section on task mutators for more information. • cbind(data) data.frame() -> self Extends the DataBackend with additional columns. The row ids must be provided as column in data (with column name matching the primary key name of the DataBackend). If this column is missing, it is assumed that the rows are exactly in the order of t$row_ids. See the section on task mutators for more information.

• rbind(data)
data.frame() -> self
Extends the DataBackend with additional rows. The new row ids must be provided as column in data. If this column is missing, new row ids are constructed automatically. See the section on task mutators for more information.

• replace_features(data)
data.frame() -> self
Replaces some features of the task by constructing a completely new DataBackendDataTable. This operation is similar to calling select() and cbind(), but explicitly copies the data. See the section on task mutators for more information.

• droplevels(cols = NULL)
character -> self
Updates the cache of stored factor levels, removing all levels not present in the set of active rows. cols defaults to all columns with storage type "character", "factor", or "ordered".

See also

Other Task: TaskClassif, TaskRegr, Task, mlr_generators, mlr_tasks

Examples

task = TaskSupervised\$new("iris", task_type = "classif", backend = iris, target = "Species")