Resamplings

Resamplings split the observations multiple times into two sets: training and test. The former is used to fit the model, the latter is used to evaluate the predictions. The Resampling objects provide an abstraction for this procedure while respecting stratification as well as grouping/blocking if this is required by the Task.

If only a single split is required (i.e., a holdout split), the partition() function provides a single split into training and test set.

Example Usage

Fit a Random Forest on the Wisconsin Breast Cancer Data Set using a 3-fold cross validation.

library("mlr3verse")
Loading required package: mlr3
# retrieve the task
task = tsk("breast_cancer")

# retrieve a learner
learner = lrn("classif.ranger")

# retrieve resampling strategy
resampling = rsmp("cv", folds = 3)

# perform resampling
rr = resample(task, learner, resampling)
INFO  [11:16:43.509] [mlr3] Applying learner 'classif.ranger' on task 'breast_cancer' (iter 1/3)
INFO  [11:16:44.055] [mlr3] Applying learner 'classif.ranger' on task 'breast_cancer' (iter 2/3)
INFO  [11:16:44.123] [mlr3] Applying learner 'classif.ranger' on task 'breast_cancer' (iter 3/3)
rr
<ResampleResult> with 3 resampling iterations
       task_id     learner_id resampling_id iteration     prediction_test
 breast_cancer classif.ranger            cv         1 <PredictionClassif>
 breast_cancer classif.ranger            cv         2 <PredictionClassif>
 breast_cancer classif.ranger            cv         3 <PredictionClassif>
 warnings errors
        0      0
        0      0
        0      0