12.7 Spatial Resampling

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

comparison of CV