createDummyFeatures: Generate dummy variables for factor features.

View source: R/createDummyFeatures.R

createDummyFeaturesR Documentation

Generate dummy variables for factor features.

Description

Replace all factor features with their dummy variables. Internally model.matrix is used. Non factor features will be left untouched and passed to the result.

Usage

createDummyFeatures(
  obj,
  target = character(0L),
  method = "1-of-n",
  cols = NULL
)

Arguments

obj

(data.frame | Task)
Input data.

target

(character(1) | character(2) | character(n.classes))
Name(s) of the target variable(s). Only used when obj is a data.frame, otherwise ignored. If survival analysis is applicable, these are the names of the survival time and event columns, so it has length 2. For multilabel classification these are the names of logical columns that indicate whether a class label is present and the number of target variables corresponds to the number of classes.

method

(character(1))
Available are:

"1-of-n":

For n factor levels there will be n dummy variables.

"reference":

There will be n-1 dummy variables leaving out the first factor level of each variable.

Default is ā€œ1-of-nā€.

cols

(character)
Columns to create dummy features for. Default is to use all columns.

Value

data.frame | Task. Same type as obj.

See Also

Other eda_and_preprocess: capLargeValues(), dropFeatures(), mergeSmallFactorLevels(), normalizeFeatures(), removeConstantFeatures(), summarizeColumns(), summarizeLevels()


mlr documentation built on June 22, 2024, 10:51 a.m.