mlr3 (version 0.1.0-9000)

resample: Resample a Learner on a Task

Description

Runs a resampling (possibly in parallel).

Usage

resample(task, learner, resampling, ctrl = list())

Arguments

task

:: (Task | character(1)) Object of type Task. Instead if a Task object, it is also possible to provide a key to retrieve a task from the mlr_tasks dictionary.

learner

:: (Learner | character(1)) Object of type Learner. Instead if a Learner object, it is also possible to provide a key to retrieve a learner from the mlr_learners dictionary.

resampling

:: (Resampling | character(1)) Object of type Resampling. Instead if a Resampling object, it is also possible to provide a key to retrieve a resampling from the mlr_resamplings dictionary.

ctrl

:: named list() Object to control learner execution. See mlr_control() for details.

Value

ResampleResult.

Parallelization

This function can be parallelized with the future package. One jobs is one resampling iteration, and all jobs are forwarded to the future package together. To select a parallel backend, use future::plan().

Examples

Run this code
# NOT RUN {
task = mlr_tasks$get("iris")
learner = mlr_learners$get("classif.rpart")
resampling = mlr_resamplings$get("cv")

# explicitly instantiate the resampling for this task for reproduciblity
set.seed(123)
resampling$instantiate(task)

rr = resample(task, learner, resampling)
print(rr)

# retrieve performance
rr$performance("classif.ce")
rr$aggregate("classif.ce")

# merged prediction objects of all resampling iterations
pred = rr$prediction
pred$confusion

# Repeat resampling with featureless learner
rr.featureless = resample(task, "classif.featureless", resampling)

# Combine the ResampleResults into a BenchmarkResult
bmr = rr$combine(rr.featureless)
print(bmr)
# }

Run the code above in your browser using DataCamp Workspace