Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predict.Learner

Predict Method for Learners


Description

Extends the generic stats::predict() with a method for Learner. Note that this function is intended as glue code to be used in third party packages. We recommend to work with the Learner directly, i.e. calling learner$predict() or learner$predict_newdata() directly.

Performs the following steps:

  • Sets additional hyperparameters passed to this function.

  • Creates a Prediction object by calling learner$predict_newdata().

  • Returns (subset of) Prediction.

Usage

## S3 method for class 'Learner'
predict(object, newdata, predict_type = NULL, ...)

Arguments

object

(Learner)
Any Learner.

newdata

(data.frame())
New data to predict on.

predict_type

(character(1))
The predict type to return. Set to <Prediction> to retrieve the complete Prediction object. If set to NULL (default), the first predict type for the respective class of the Learner as stored in mlr_reflections is used.

...

(any)
Hyperparameters to pass down to the Learner.

Examples

task = tsk("spam")

learner = lrn("classif.rpart", predict_type = "prob")
learner$train(task)
predict(learner, task$data(1:3), predict_type = "response")
predict(learner, task$data(1:3), predict_type = "prob")
predict(learner, task$data(1:3), predict_type = "<Prediction>")

mlr3

Machine Learning in R - Next Generation

v0.11.0
LGPL-3
Authors
Michel Lang [cre, aut] (<https://orcid.org/0000-0001-9754-0393>), Bernd Bischl [aut] (<https://orcid.org/0000-0001-6002-6980>), Jakob Richter [aut] (<https://orcid.org/0000-0003-4481-5554>), Patrick Schratz [aut] (<https://orcid.org/0000-0003-0748-6624>), Giuseppe Casalicchio [ctb] (<https://orcid.org/0000-0001-5324-5966>), Stefan Coors [ctb] (<https://orcid.org/0000-0002-7465-2146>), Quay Au [ctb] (<https://orcid.org/0000-0002-5252-8902>), Martin Binder [aut], Marc Becker [ctb] (<https://orcid.org/0000-0002-8115-0400>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.