Learner: Learner Class

Description Format Construction Fields Methods Optional Extractors Setting Hyperparameters See Also


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

Learners consist of the following parts:

Predefined learners are stored in the mlr3misc::Dictionary mlr_learners, e.g. classif.rpart or regr.rpart. A guide on how to extend mlr3 with custom learners can be found in the mlr3book.


R6::R6Class object.


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(), predict_types = character(),
     feature_types = character(), properties = character(), packages = character())



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:

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 = lrn("classif.rpart")
lrn$param_set$values = list(minsplit = 3, cp = 0.01)

Note that this operation replaces 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")))

See Also

Other Learner: LearnerClassif, LearnerRegr, mlr_learners

mllg/mlr3 documentation built on Sept. 27, 2019, 9:38 a.m.