mlr_pipeops_learner_cv {mlr3pipelines}R Documentation

Wrap a Learner into a PipeOp with Cross-validated Predictions as Features

Description

Wraps an mlr3::Learner into a PipeOp.

Returns cross-validated predictions during training as a Task and stores a model of the Learner trained on the whole data in ⁠$state⁠. This is used to create a similar Task during prediction.

The Task gets features depending on the capsuled Learner's ⁠$predict_type⁠. If the Learner's ⁠$predict.type⁠ is "response", a feature ⁠<ID>.response⁠ is created, for ⁠$predict.type⁠ "prob" the ⁠<ID>.prob.<CLASS>⁠ features are created, and for ⁠$predict.type⁠ "se" the new columns are ⁠<ID>.response⁠ and ⁠<ID>.se⁠. ⁠<ID>⁠ denotes the ⁠$id⁠ of the PipeOpLearnerCV object.

Inherits the ⁠$param_set⁠ (and therefore ⁠$param_set$values⁠) from the Learner it is constructed from.

PipeOpLearnerCV can be used to create "stacking" or "super learning" Graphs that use the output of one Learner as feature for another Learner. Because the PipeOpLearnerCV erases the original input features, it is often useful to use PipeOpFeatureUnion to bind the prediction Task to the original input Task.

Format

R6Class object inheriting from PipeOpTaskPreproc/PipeOp.

Construction

PipeOpLearnerCV$new(learner, id = NULL, param_vals = list())

Input and Output Channels

PipeOpLearnerCV has one input channel named "input", taking a Task specific to the Learner type given to learner during construction; both during training and prediction.

PipeOpLearnerCV has one output channel named "output", producing a Task specific to the Learner type given to learner during construction; both during training and prediction.

The output is a task with the same target as the input task, with features replaced by predictions made by the Learner. During training, this prediction is the out-of-sample prediction made by resample, during prediction, this is the ordinary prediction made on the data by a Learner trained on the training phase data.

State

The ⁠$state⁠ is set to the ⁠$state⁠ slot of the Learner object, together with the ⁠$state⁠ elements inherited from the PipeOpTaskPreproc. It is a named list with the inherited members, as well as:

Parameters

The parameters are the parameters inherited from the PipeOpTaskPreproc, as well as the parameters of the Learner wrapped by this object. Besides that, parameters introduced are:

Internals

The ⁠$state⁠ is currently not updated by prediction, so the ⁠$state$predict_log⁠ and ⁠$state$predict_time⁠ will always be NULL.

Fields

Fields inherited from PipeOp, as well as:

Methods

Methods inherited from PipeOpTaskPreproc/PipeOp.

See Also

https://mlr-org.com/pipeops.html

Other Meta PipeOps: mlr_pipeops_learner

Examples


library("mlr3")

task = tsk("iris")
learner = lrn("classif.rpart")

lrncv_po = po("learner_cv", learner)
lrncv_po$learner$predict_type = "response"

nop = mlr_pipeops$get("nop")

graph = gunion(list(
  lrncv_po,
  nop
)) %>>% po("featureunion")

graph$train(task)

graph$pipeops$classif.rpart$learner$predict_type = "prob"

graph$train(task)


[Package mlr3pipelines version 0.5.2 Index]