Create a classification, regression, survival, cluster, cost-sensitive classification or multilabel task.

The task encapsulates the data and specifies - through its subclasses - the type of the task. It also contains a description object detailing further aspects of the data.

Useful operators are: getTaskFormula, getTaskFeatureNames, getTaskData, getTaskTargets, and subsetTask.

Object members:

env (environment)

Environment where data for the task are stored. Use getTaskData in order to access it.

weights (numeric)

See argument. NULL if not present.

blocking (factor)

See argument. NULL if not present.

task.desc (TaskDesc)

Encapsulates further information about the task.

makeClassifTask(id = deparse(substitute(data)), data, target,
  weights = NULL, blocking = NULL, coordinates = NULL,
  positive = NA_character_, = "warn", = TRUE)

makeClusterTask(id = deparse(substitute(data)), data, weights = NULL, blocking = NULL, coordinates = NULL, = "warn", = TRUE)

makeCostSensTask(id = deparse(substitute(data)), data, costs, blocking = NULL, coordinates = NULL, = "warn", = TRUE)

makeMultilabelTask(id = deparse(substitute(data)), data, target, weights = NULL, blocking = NULL, coordinates = NULL, = "warn", = TRUE)

makeRegrTask(id = deparse(substitute(data)), data, target, weights = NULL, blocking = NULL, coordinates = NULL, = "warn", = TRUE)

makeSurvTask(id = deparse(substitute(data)), data, target, weights = NULL, blocking = NULL, coordinates = NULL, = "warn", = TRUE)


(character(1)) Id string for object. Default is the name of the R variable passed to data.


(data.frame) A data frame containing the features and target variable(s).


(character(1) | character(2) | character(n.classes)) Name(s) of the target variable(s). For survival analysis these are the names of the survival time and event columns, so it has length 2. For multilabel classification it contains the names of the logical columns that encode whether a label is present or not and its length corresponds to the number of classes.


(numeric) Optional, non-negative case weight vector to be used during fitting. Cannot be set for cost-sensitive learning. Default is NULL which means no (= equal) weights.


(factor) An optional factor of the same length as the number of observations. Observations with the same blocking level “belong together”. Specifically, they are either put all in the training or the test set during a resampling iteration. Default is NULL which means no blocking.


(data.frame) Coordinates of a spatial data set that will be used for spatial partitioning of the data in a spatial cross-validation resampling setting. Coordinates have to be numeric values. Provided data.frame needs to have the same number of rows as data and consist of at least two dimensions.


(character(1)) Positive class for binary classification (otherwise ignored and set to NA). Default is the first factor level of the target attribute.

(character(1)) Should some basic cleaning up of data be performed? Currently this means removing empty factor levels for the columns. Possible choices are: “no” = Don't do it. “warn” = Do it but warn about it. “quiet” = Do it but keep silent. Default is “warn”.

(logical(1)) Should sanity of data be checked initially at task creation? You should have good reasons to turn this off (one might be speed). Default is TRUE.


(data.frame) A numeric matrix or data frame containing the costs of misclassification. We assume the general case of observation specific costs. This means we have n rows, corresponding to the observations, in the same order as data. The columns correspond to classes and their names are the class labels (if unnamed we use y1 to yk as labels). Each entry (i,j) of the matrix specifies the cost of predicting class j for observation i.


For multilabel classification we assume that the presence of labels is encoded via logical columns in data. The name of the column specifies the name of the label. target is then a char vector that points to these columns.

Functional data can be added to a task via matrix columns. For more information refer to makeFunctionalData.



See Also

Other costsens: makeCostSensClassifWrapper, makeCostSensRegrWrapper, makeCostSensWeightedPairsWrapper

  • makeClassifTask
  • makeClusterTask
  • makeCostSensTask
  • makeMultilabelTask
  • makeRegrTask
  • makeSurvTask
  • Task
  • ClassifTask
  • RegrTask
  • SurvTask
  • CostSensTask
  • ClusterTask
  • MultilabelTask
if (requireNamespace("mlbench")) {

  makeClassifTask(data = iris, target = "Species")
  makeRegrTask(data = BostonHousing, target = "medv")
  # an example of a classification task with more than those standard arguments:
  blocking = factor(c(rep(1, 51), rep(2, 300)))
  makeClassifTask(id = "myIonosphere", data = Ionosphere, target = "Class",
    positive = "good", blocking = blocking)
  makeClusterTask(data = iris[, -5L])
# }
Documentation reproduced from package mlr, version 2.12.1, License: BSD_2_clause + file LICENSE

Community examples

Looks like there are no examples yet.