2.3 Learners

Objects of class mlr3::Learner provide a unified interface to many popular machine learning algorithms in R. They consist of methods to train and predict a model for a mlr3::Task and provide meta-information about the learners, such as the hyperparameters you can set.

The package ships with a minimal set of classification and regression learners to avoid lots of dependencies:

Some of the most popular learners are connected via the mlr3learners package:

  • (penalized) linear and logistic regression
  • \(k\)-Nearest Neighbors regression and classification
  • Linear and Quadratic Discriminant Analysis
  • Naive Bayes
  • Support-Vector machines
  • Gradient Boosting
  • Random Regression Forests and Random Classification Forests
  • Kriging

More learners are collected on GitHub in the mlr3learners organization. Their state is also listed on the wiki of the mlr3learners repository.

The base class of each learner is Learner, specialized for regression as LearnerRegr and for classification as LearnerClassif. In contrast to the Task, the creation of a custom Learner is usually not required and a more advanced topic. Hence, we refer the reader to Section 6.1 and proceed with an overview of the interface of already implemented learners.

2.3.1 Predefined Learners

Similar to mlr_tasks, the Dictionary mlr_learners can be queried for available learners:

Each learner has the following information:

  • feature_types: the type of features the learner can deal with.
  • packages: the packages required to train a model with this learner and make predictions.
  • properties: additional properties and capabilities. For example, a learner has the property “missings” if it is able to handle missing feature values, and “importance” if it computes and allows to extract data on the relative importance of the features. A complete list of these is available in the mlr3 reference on regression learners and classification learners.
  • predict_types: possible prediction types. For example, a classification learner can predict labels (“response”) or probabilities (“prob”). For a complete list of possible predict types see the mlr3 reference.

For a tabular overview of integrated learners, see Section 10.1.

You can get a specific learner using its id, listed under key in the dictionary:

The field param_set stores a description of the hyperparameters the learner has, their ranges, defaults, and current values:

The set of current hyperparameter values is stored in the values field of the param_set field. You can change the current hyperparameter values by assigning a named list to this field:

Note that this operation just overwrites all previously set parameters. If you just want to add or update hyperparameters, you can use mlr3misc::insert_named():

This updates cp to 0.02, sets minsplit to 2 and keeps the previously set parameter xval.

Again, there is an alternative to writing down the lengthy mlr_learners$get() part: lrn(). This function additionally allows to construct learners with specific hyperparameters or settings of a different identifier in one go:

If you pass hyperparameters here, they are added to the parameters in a insert_named()-fashion.