12.7 Spatial Resampling
= mlr3::rsmp("repeated_spcv_coords", folds = 5, repeats = 100) resampling
# approx 15 seconds of run time
# reduce verbosity
::get_logger("mlr3")$set_threshold("warn")
lgr# run spatial cross-validation and save it to resample result glm (rr_glm)
= mlr3::resample(task = task,
rr_spcv_glm learner = learner,
resampling = resampling)
# compute the AUROC as a data.table
= rr_spcv_glm$score(measure = mlr3::msr("classif.auc"))
score_spcv_glm # keep only the columns you need
= score_spcv_glm[, .(task_id, learner_id, resampling_id,
score_spcv_glm classif.auc)]
# loading the textbook data directly to save computation time
= readRDS("extdata/12-bmr_score.rds")
score = score[learner_id == "classif.log_reg" &
score_spcv_glm == "repeated_spcv_coords"] resampling_id
# average AUROC
mean(score_spcv_glm$classif.auc) |> round(2)
## [1] 0.77
![](images/boxplot-cv-1.png)
comparison of CV