This is the abstract base class for learner objects like LearnerClassif and LearnerRegr.

Learners consist of the following parts:

• Methods train() and predict() to perform the respective steps.

• The fitted model, after calling train().

• 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.

## Format

R6::R6Class object.

## Construction

Note: This object is typically constructed via a derived classes, e.g. LearnerClassif or LearnerRegr.

l = Learner$new(id, task_type, param_set = ParamSet$new(), param_vals = list(), predict_types = character(),
feature_types = character(), properties = character(), packages = character())

• id :: character(1)
Identifier for the learner.

• task_type :: character(1)
Type of the task the learner can operator on. E.g., "classif" or "regr".

• param_set :: paradox::ParamSet
Set of hyperparameters.

• param_vals :: named list()
List of hyperparameter settings.

• predict_types :: character()
Supported predict types. Must be a subset of mlr_reflections$learner_predict_types. • feature_types :: character() Feature types the learner operates on. Must be a subset of mlr_reflections$task_feature_types.

• properties :: character()
Set of properties of the learner. Must be a subset of mlr_reflections$learner_properties. • data_formats :: character() Vector of supported data formats which can be processed during $train() and $predict(). Defaults to "data.table". • packages :: character() Set of required packages. Note that these packages will be loaded via requireNamespace(), and are not attached. ## Fields • id :: character(1) Identifier of the learner. • task_type :: character(1) Stores the type of class this learner can operate on, e.g. "classif" or "regr". A complete list of task types is stored in mlr_reflections$task_types.

• param_set :: paradox::ParamSet
Description of available hyperparameters and hyperparameter settings.

• predict_types :: character()
Stores the possible predict types the learner is capable of. A complete list of candidate predict types, grouped by task type, is stored in mlr_reflections$learner_predict_types. • predict_type :: character(1) Stores the currently selected predict type. Must be an element of l$predict_types.

• feature_types :: character()
Stores the feature types the learner can handle, e.g. "logical", "numeric", or "factor". A complete list of candidate feature types, grouped by task type, is stored in mlr_reflections$task_feature_types. • properties :: character() Stores a set of properties/capabilities the learner has. A complete list of candidate properties, grouped by task type, is stored in mlr_reflections$learner_properties.

• packages :: character()
Stores the names of required packages.

• fallback :: (Learner | NULL)
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 mlr_control().

• hash :: character(1)
Hash (unique identifier) for this object.

## Methods

• params(tag)
character(1) -> named list()
Returns a list of hyperparameter settings from param_set where the corresponding parameters in param_set are tagged with tag. I.e., l$params("train") returns all settings of hyperparameters relevant in the training step. • train(task) Task -> self Train the learner on the complete Task. The resulting model is stored in l$model.

• predict(task)
Uses l$model (fitted during train()) to return a Prediction object. ## Optional Extractors 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 numeric(). 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 character(). The learner must be tagged with property "selected_features". • oob_error(...): Returns the out-of-bag error of the model as numeric(1). The learner must be tagged with property "oob_error". ## Setting Hyperparameters 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 values: 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 mlr3misc::insert_named():

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")))


Other Learner: LearnerClassif, LearnerRegr, mlr_learners