This Learner specializes Learner for classification problems:
task_typeis set to"classif".Creates Predictions of class PredictionClassif.
Possible values for
predict_typesare:"response": Predicts a class label for each observation in the test set."prob": Predicts the posterior probability for each class for each observation in the test set.
Additional learner properties include:
"twoclass": The learner works on binary classification problems."multiclass": The learner works on multiclass classification problems.
Predefined learners can be found in the dictionary mlr_learners. Essential classification learners can be found in this dictionary after loading mlr3learners. Additional learners are implement in the Github package https://github.com/mlr-org/mlr3extralearners.
See also
Chapter in the mlr3book: https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-learners
Package mlr3learners for a solid collection of essential learners.
Package mlr3extralearners for more learners.
as.data.table(mlr_learners)for a table of available Learners in the running session (depending on the loaded packages).mlr3pipelines to combine learners with pre- and postprocessing steps.
Package mlr3viz for some generic visualizations.
Extension packages for additional task types:
mlr3proba for probabilistic supervised regression and survival analysis.
mlr3cluster for unsupervised clustering.
mlr3tuning for tuning of hyperparameters, mlr3tuningspaces for established default tuning spaces.
Other Learner:
Learner,
LearnerRegr,
mlr_learners,
mlr_learners_classif.debug,
mlr_learners_classif.featureless,
mlr_learners_classif.rpart,
mlr_learners_regr.debug,
mlr_learners_regr.featureless,
mlr_learners_regr.rpart
Super class
mlr3::Learner -> LearnerClassif
Methods
Method new()
Creates a new instance of this R6 class.
Usage
LearnerClassif$new(
id,
param_set = ps(),
predict_types = "response",
feature_types = character(),
properties = character(),
packages = character(),
label = NA_character_,
man = NA_character_
)Arguments
id(
character(1))
Identifier for the new instance.param_set(paradox::ParamSet)
Set of hyperparameters.predict_types(
character())
Supported predict types. Must be a subset ofmlr_reflections$learner_predict_types.feature_types(
character())
Feature types the learner operates on. Must be a subset ofmlr_reflections$task_feature_types.properties(
character())
Set of properties of the Learner. Must be a subset ofmlr_reflections$learner_properties. The following properties are currently standardized and understood by learners in mlr3:"missings": The learner can handle missing values in the data."weights": The learner supports observation weights."offset": The learner can incorporate offset values to adjust predictions."importance": The learner supports extraction of importance scores, i.e. comes with an$importance()extractor function (see section on optional extractors in Learner)."selected_features": The learner supports extraction of the set of selected features, i.e. comes with a$selected_features()extractor function (see section on optional extractors in Learner)."oob_error": The learner supports extraction of estimated out of bag error, i.e. comes with aoob_error()extractor function (see section on optional extractors in Learner)."validation": The learner can use a validation task during training."internal_tuning": The learner is able to internally optimize hyperparameters (those are also tagged with"internal_tuning")."marshal": To save learners with this property, you need to call$marshal()first. If a learner is in a marshaled state, you call first need to call$unmarshal()to use its model, e.g. for prediction."hotstart_forward": The learner supports to hotstart a model forward."hotstart_backward": The learner supports hotstarting a model backward.`"featureless": The learner does not use features.
packages(
character())
Set of required packages. A warning is signaled by the constructor if at least one of the packages is not installed, but loaded (not attached) later on-demand viarequireNamespace().label(
character(1))
Label for the new instance.man(
character(1))
String in the format[pkg]::[topic]pointing to a manual page for this object. The referenced help package can be opened via method$help().
Method predict_newdata_fast()
Predicts outcomes for new data in newdata using the model fitted during $train().
This method is faster than $predict_newdata() as it skips assertions, type conversions, encapsulation, and logging.
Unlike $predict_newdata(), this method does not return a Prediction object.
Instead, it returns a list with either a "response" or "prob" element, depending on the prediction type.
Note that state$predict_time and state$log will remain empty after using this method.
Some learners may not support this method and may fail when it is called.
Prefer $predict_newdata() unless performance is critical.
If the model was trained via resample() or benchmark(), you must pass the associated task object stored in the corresponding ResampleResult or BenchmarkResult.
Arguments
newdatadata.table::data.table()
New data to predict on.task(Task).
Returns
list() with elements "response" or "prob" depending on the predict type.
Examples
# get all classification learners from mlr_learners:
lrns = mlr_learners$mget(mlr_learners$keys("^classif"))
names(lrns)
#> [1] "classif.debug" "classif.featureless" "classif.rpart"
# get a specific learner from mlr_learners:
lrn = lrn("classif.rpart")
print(lrn)
#>
#> ── <LearnerClassifRpart> (classif.rpart): Classification Tree ──────────────────
#> • Model: -
#> • Parameters: xval=0
#> • Packages: mlr3 and rpart
#> • Predict Types: [response] and prob
#> • Feature Types: logical, integer, numeric, factor, and ordered
#> • Encapsulation: none (fallback: -)
#> • Properties: importance, missings, multiclass, selected_features, twoclass,
#> and weights
#> • Other settings: use_weights = 'use'
# train the learner:
task = tsk("penguins")
lrn$train(task, 1:200)
# predict on new observations:
lrn$predict(task, 201:344)$confusion
#> truth
#> response Adelie Chinstrap Gentoo
#> Adelie 0 62 1
#> Chinstrap 0 0 0
#> Gentoo 0 6 75