Encodes columns of type
PipeOpEncodeLmer() converts factor levels of each factorial column to the
estimated coefficients of a simple random intercept model.
Models are fitted with the glmer function of the lme4 package and are
of the type
target ~ 1 + (1 | factor).
If the task is a regression task, the numeric target
variable is used as dependent variable and the factor is used for grouping.
If the task is a classification task, the target variable is used as dependent variable
and the factor is used for grouping.
If the target variable is multiclass, for each level of the multiclass target variable,
binary "one vs. rest" models are fitted.
For training, multiple models can be estimated in a cross-validation scheme to ensure that the same factor level does not always result in identical values in the converted numerical feature. For prediction, a global model (which was fitted on all observations during training) is used for each factor. New factor levels are converted to the value of the intercept coefficient of the global model for prediction. NAs are ignored by the CPO.
$affect_columns functionality to only encode a subset of
columns, or only encode columns of a certain type.
PipeOpEncodeLmer$new(id = "encodelmer", param_vals = list())
Identifier of resulting object, default
param_vals :: named
List of hyperparameter settings, overwriting the hyperparameter settings that would otherwise be set during construction. Default
Input and output channels are inherited from
The output is the input
Task with all affected
ordered parameters encoded according to the
$state is a named
list with the
$state elements inherited from
PipeOpTaskPreproc, as well as:
Levels of the target columns.
control :: a named
List of coefficients learned via
If “fast_optim” is
TRUE (default), a faster (up to 50 percent)
optimizer from the nloptr package is used when fitting the lmer models.
This uses additional stopping criteria which can give suboptimal results.
lme4::glmer. This is relatively inefficient for features with a large number of levels.
library("mlr3") poe = po("encodelmer") task = TaskClassif$new("task", data.table::data.table( x = c("a", "a", "a", "b", "b"), y = c("a", "a", "b", "b", "b")), "x")#> Error: Target column 'x' must be a factor#> Error in vapply(.x, .f, FUN.VALUE = .value, USE.NAMES = FALSE, ...): object 'task' not foundpoe$state#> NULL