2.3 Learners

发布时间:2025-08-22 23:42

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:

mlr_learners_classif.featureless: Simple baseline classification learner, constantly predicts the label that is most frequent in the training set. mlr_learners_classif.rpart: Single classification tree from rpart. mlr_learners_regr.featureless: Simple baseline regression learner, constantly predicts with the mean. mlr_learners_regr.rpart: Single regression tree from rpart.

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. Below a graphical illustration of the role of a learner:

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.

Predefined Learners

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

## <DictionaryLearner> with 24 stored values ## Keys: classif.cv_glmnet, classif.debug, classif.featureless, ## classif.glmnet, classif.kknn, classif.lda, classif.log_reg, ## classif.multinom, classif.naive_bayes, classif.qda, classif.ranger, ## classif.rpart, classif.svm, classif.xgboost, regr.cv_glmnet, ## regr.featureless, regr.glmnet, regr.kknn, regr.km, regr.lm, ## regr.ranger, regr.rpart, regr.svm, regr.xgboost

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

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

## <LearnerClassifRpart:classif.rpart> ## * Model: - ## * Parameters: xval=0 ## * Packages: rpart ## * Predict Type: response ## * Feature types: logical, integer, numeric, factor, ordered ## * Properties: importance, missings, multiclass, selected_features, ## twoclass, weights

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

## ParamSet: ## id class lower upper levels default value ## 1: minsplit ParamInt 1 Inf 20 ## 2: minbucket ParamInt 1 Inf <NoDefault> ## 3: cp ParamDbl 0 1 0.01 ## 4: maxcompete ParamInt 0 Inf 4 ## 5: maxsurrogate ParamInt 0 Inf 5 ## 6: maxdepth ParamInt 1 30 30 ## 7: usesurrogate ParamInt 0 2 2 ## 8: surrogatestyle ParamInt 0 1 0 ## 9: xval ParamInt 0 Inf 10 0

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:

## <LearnerClassifRpart:classif.rpart> ## * Model: - ## * Parameters: cp=0.01, xval=0 ## * Packages: rpart ## * Predict Type: response ## * Feature types: logical, integer, numeric, factor, ordered ## * Properties: importance, missings, multiclass, selected_features, ## twoclass, weights

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():

## <LearnerClassifRpart:classif.rpart> ## * Model: - ## * Parameters: cp=0.02, xval=0, minsplit=2 ## * Packages: rpart ## * Predict Type: response ## * Feature types: logical, integer, numeric, factor, ordered ## * Properties: importance, missings, multiclass, selected_features, ## twoclass, weights

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:

## <LearnerClassifRpart:rp> ## * Model: - ## * Parameters: xval=0, cp=0.001 ## * Packages: rpart ## * Predict Type: response ## * Feature types: logical, integer, numeric, factor, ordered ## * Properties: importance, missings, multiclass, selected_features, ## twoclass, weights

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

网址:2.3 Learners https://klqsh.com/news/view/178926

相关内容

2.3 Learners
Macmillan English Dictionary for Advanced Learners
Best LMS Software to Use When Working Remotely: Top 7 Options for Your Team
1天带货2.3亿的网红患焦虑症,躯体化全身疼痛,有钱了也不快乐吗
薛凯琪40岁冻龄背后:2.3亿债务与36公斤体重的生死较量
10 Best Remote Training Software for Enterprises (2024 Update)
Dictionary of Learners — mlr
李白2.3亿的播放是造价还是实力!
银行存款理财比活期利息高2.3倍
Comprehensive Car Insurance Victoria quotes

随便看看