5.1 Objects

Again, we consider the iris task and a simple classification tree here.

library(mlr3)
task = mlr_tasks$get("iris")
learner = mlr_learners$get("classif.rpart")

Additionally, we need to define how we want to resample. mlr3 comes with the following resampling strategies implemented:

mlr_resamplings$keys()
## [1] "bootstrap"   "custom"      "cv"         
## [4] "cv3"         "holdout"     "repeated_cv"
## [7] "subsampling"

Additional resampling methods for special use cases will be available via extension packages, such as mlr3spatiotemporal for spatial data (still in development).

The experiment conducted in the introduction on train/predict/score is equivalent to a simple “holdout”, so let’s consider this one first.

resampling = mlr_resamplings$get("holdout")
print(resampling)
## <ResamplingHoldout> with 1 iterations
## Instantiated: FALSE
## Parameters: ratio=0.6667
## 
## Public: clone, duplicated_ids, format, hash,
##   id, instance, instantiate, is_instantiated,
##   iters, param_set, task_hash, test_set,
##   train_set
print(resampling$param_set$values)
## $ratio
## [1] 0.6667

To change the ratio to \(0.8\), we simply overwrite the slot:

resampling$param_set$values = list(ratio = 0.8)