
Runs a resampling (possibly in parallel).
resample(task, learner, resampling, store_models = FALSE)
:: Task.
:: Learner.
:: Resampling.
:: logical(1)
Keep the fitted model after the test set has been predicted?
Set to TRUE
if you want to further analyse the models or want to
extract information like variable importance.
This function can be parallelized with the future package.
One job is one resampling iteration, and all jobs are send to an apply function
from future.apply in a single batch.
To select a parallel backend, use future::plan()
.
The mlr3 uses the lgr package for logging.
lgr supports multiple log levels which can be queried with
getOption("lgr.log_levels")
.
To suppress output and reduce verbosity, you can lower the log from the
default level "info"
to "warn"
:
lgr::get_logger("mlr3")$set_threshold("warn")
To get additional log output for debugging, increase the log level to "debug"
or "trace"
:
lgr::get_logger("mlr3")$set_threshold("debug")
To log to a file or a data base, see the documentation of lgr::lgr-package.
# NOT RUN {
task = tsk("iris")
learner = lrn("classif.rpart")
resampling = rsmp("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$score(msr("classif.ce"))
rr$aggregate(msr("classif.ce"))
# merged prediction objects of all resampling iterations
pred = rr$prediction()
pred$confusion
# Repeat resampling with featureless learner
rr_featureless = resample(task, lrn("classif.featureless"), resampling)
# Convert results to BenchmarkResult, then combine them
bmr1 = as_benchmark_result(rr)
bmr2 = as_benchmark_result(rr_featureless)
print(bmr1$combine(bmr2))
# }
Run the code above in your browser using DataLab