Learners consist of the following parts:
predict() to perform the respective steps.
The fitted model, after calling
A paradox::ParamSet which stores meta-information about available hyperparameters, and also stores hyperparameter settings.
Meta-information about the requirements and capabilities of the learner.
Predefined learners are stored in mlr_learners.
l = Learner$new(id, task_type, param_set = ParamSet$new(), param_vals = list(), predict_types = character(), feature_types = character(), properties = character(), packages = character())
Identifier for the learner.
Type of the task the learner can operator on. E.g.,
param_set :: paradox::ParamSet
Set of hyperparameters.
param_vals :: named
List of hyperparameter settings.
Feature types the learner operates on. Must be a subset of
Vector of supported data formats which can be processed during
Identifier of the learner.
param_set :: paradox::ParamSet
Description of available hyperparameters and hyperparameter settings.
Stores the possible predict types the learner is capable of. A complete list of candidate predict types, grouped by task type, is stored in
Stores the currently selected predict type. Must be an element of
Stores the feature types the learner can handle, e.g.
A complete list of candidate feature types, grouped by task type, is stored in
Stores the names of required packages.
fallback :: (Learner |
Optionally stores a second Learner which is activated as fallback if this first Learner fails during train or predict. This mechanism is disabled unless you explicitly assign a learner to this slot. Additionally, you need to enable encapsulation for the fallback learner to work, see
Hash (unique identifier) for this object.
character(1) -> named
Returns a list of hyperparameter settings from
param_set where the corresponding parameters in
param_set are tagged
l$params("train") returns all settings of hyperparameters relevant in the training step.
Specific learner implementations are free to implement additional getters to ease the access of certain parts of the model in the inherited subclasses.
For the following operations, extractors are standardized:
importance(...): Returns a feature importance score as
The learner must be tagged with property "importance".
The higher the score, the more important the variable. The returned vector is named with feature names and sorted in decreasing order. Note that the model might omit features it has not used at all.
selected_features(...): Returns a subset of selected features as
The learner must be tagged with property "selected_features".
oob_error(...): Returns the out-of-bag error of the model as
The learner must be tagged with property "oob_error".
All information about hyperparameters is stored in the slot
param_set which is a paradox::ParamSet.
The printer gives an overview about the ids of available hyperparameters, their storage type, lower and upper bounds,
possible levels (for factors), default values and assigned values.
To set hyperparameters, assign a named list to the subslot
lrn = mlr_learners$get("classif.rpart") lrn$param_set$values = list(minsplit = 3, cp = 0.01)
Note that this operation erases all previously set hyperparameter values.
If you only intend to change one specific hyperparameter value and leave the others as-is, you can use the helper function
lrn$param_set$values = mlr3misc::insert_named(lrn$param_set$values, list(cp = 0.001))
If the learner has additional hyperparameters which are not encoded in the ParamSet, you can easily extend the learner. Here, we add a hyperparameter with id "foo" possible levels "a" and "b":
lrn$param_set$add(paradox::ParamFct$new("foo", levels = c("a", "b")))