Useful in trainLearner when you add a learning machine to the package.

getTaskData(
  task,
  subset = NULL,
  features,
  target.extra = FALSE,
  recode.target = "no",
  functionals.as = "dfcols"
)

Arguments

task

(Task)
The task.

subset

(integer | logical | NULL)
Selected cases. Either a logical or an index vector. By default NULL if all observations are used.

features

(character | integer | logical)
Vector of selected inputs. You can either pass a character vector with the feature names, a vector of indices, or a logical vector.
In case of an index vector each element denotes the position of the feature name returned by getTaskFeatureNames.
Note that the target feature is always included in the resulting task, you should not pass it here. Default is to use all features.

target.extra

(logical(1))
Should target vector be returned separately? If not, a single data.frame including the target columns is returned, otherwise a list with the input data.frame and an extra vector or data.frame for the targets. Default is FALSE.

recode.target

(character(1))
Should target classes be recoded? Supported are binary and multilabel classification and survival. Possible values for binary classification are “01”, “-1+1” and “drop.levels”. In the two latter cases the target vector is converted into a numeric vector. The positive class is coded as “+1” and the negative class either as “0” or “-1”. “drop.levels” will remove empty factor levels in the target column. In the multilabel case the logical targets can be converted to factors with “multilabel.factor”. For survival, you may choose to recode the survival times to “left”, “right” or “interval2” censored times using “lcens”, “rcens” or “icens”, respectively. See survival::Surv for the format specification. Default for both binary classification and survival is “no” (do nothing).

functionals.as

(character(1))
How to represents functional features? Option “matrix”: Keep them as matrix columns in the data.frame. Option “dfcols”: Convert them to individual numeric data.frame columns. Default is “dfcols”.

Value

Either a data.frame or a list with data.frame data and vector target.

See also

Examples

library("mlbench") data(BreastCancer) df = BreastCancer df$Id = NULL task = makeClassifTask(id = "BreastCancer", data = df, target = "Class", positive = "malignant") head(getTaskData)
#> #> 1 function (task, subset = NULL, features, target.extra = FALSE, #> 2 recode.target = "no", functionals.as = "dfcols") #> 3 { #> 4 checkTask(task, "Task") #> 5 checkTaskSubset(subset, size = task$task.desc$size) #> 6 assertLogical(target.extra)
head(getTaskData(task, features = c("Cell.size", "Cell.shape"), recode.target = "-1+1"))
#> Cell.size Cell.shape Class #> 1 1 1 -1 #> 2 4 4 -1 #> 3 1 1 -1 #> 4 8 8 -1 #> 5 1 1 -1 #> 6 10 10 1
head(getTaskData(task, subset = 1:100, recode.target = "01"))
#> Cl.thickness Cell.size Cell.shape Marg.adhesion Epith.c.size Bare.nuclei #> 1 5 1 1 1 2 1 #> 2 5 4 4 5 7 10 #> 3 3 1 1 1 2 2 #> 4 6 8 8 1 3 4 #> 5 4 1 1 3 2 1 #> 6 8 10 10 8 7 10 #> Bl.cromatin Normal.nucleoli Mitoses Class #> 1 3 1 1 0 #> 2 3 2 1 0 #> 3 3 1 1 0 #> 4 3 7 1 0 #> 5 3 1 1 0 #> 6 9 7 1 1