CPO Learners are created when a CPO gets attached to an mlr-Learner object. The resulting learner performs the operation described by the attached CPO before fitting the model specified by the Learner. It is possible to attach compound CPOs, and it is possible to attach more CPOs to a learner that is already a CPOLearner. If the attached CPO exports hyperparameters, these become part of the newly created learner and can be queried and set using functions such as getParamSet, getHyperPars, and setHyperPars.

The model created when training a CPOLearner also contains the relevant CPORetrafo information to be applied to prediction data; this can be retrieved using retrafo. The CPOInverter functionality is handled equally transparently by the model.

A CPOLearner can possibly have different LearnerProperties than the base Learner to which it is attached. This depends on the CPO's properties, see CPOProperties.

It is possible to retrieve the CPOLearner's base learner using getLearnerBare, and to get the attached CPOs using getLearnerCPO.

See also

Other CPO lifecycle related: CPOConstructor, CPOTrained, CPO, NULLCPO, %>>%(), attachCPO(), composeCPO(), getCPOClass(), getCPOConstructor(), getCPOTrainedCPO(), identicalCPO(), makeCPO()

Other CPOLearner related: attachCPO(), getLearnerBare(), getLearnerCPO()

Examples

lrn = makeLearner("classif.logreg") cpolrn = cpoScale() %>>% lrn print(cpolrn)
#> Learner classif.logreg.scale from package stats #> Type: classif #> Name: ; Short name: #> Class: CPOLearner #> Properties: numerics,factors,twoclass,prob #> Predict-Type: response #> Hyperparameters: model=FALSE #>
getLearnerBare(cpolrn) # classif.logreg Learner
#> Learner classif.logreg from package stats #> Type: classif #> Name: Logistic Regression; Short name: logreg #> Class: classif.logreg #> Properties: twoclass,numerics,factors,prob,weights #> Predict-Type: response #> Hyperparameters: model=FALSE #>
getLearnerCPO(cpolrn) # cpoScale() CPO
#> scale(center = TRUE, scale = TRUE)
getParamSet(cpolrn) # includes cpoScale hyperparameters
#> Type len Def Constr Req Tunable Trafo #> scale.center logical - TRUE - - TRUE - #> scale.scale logical - TRUE - - TRUE - #> model logical - TRUE - - FALSE -
model = train(cpolrn, pid.task) # behaves like a learner retrafo(model) # the CPORetrafo that was trained
#> CPO Retrafo chain #> [RETRAFO scale(center = TRUE, scale = TRUE)]
predict(model, pid.task) # otherwise behaves like an mlr model
#> Prediction: 768 observations #> predict.type: response #> threshold: #> time: 0.01 #> id truth response #> 1 1 pos pos #> 2 2 neg neg #> 3 3 pos pos #> 4 4 neg neg #> 5 5 pos pos #> 6 6 neg neg #> ... (#rows: 768, #cols: 3)