learner = lrn("classif.rpart")
task = tsk("pima")
resampling = rsmp("cv", folds = 3)
# save selected features callback
callback = callback_resample("selected_features",
on_resample_end = function(callback, context) {
context$learner$state$selected_features = context$learner$selected_features()
}
)
rr = resample(task, learner, resampling, callbacks = callback)
rr$learners[[1]]$state$selected_features
# holdout task callback
callback = callback_resample("holdout_task",
on_resample_before_predict = function(callback, context) {
pred = context$learner$predict(callback$state$task)
context$data_extra = list(prediction_holdout = pred)
}
)
task_holdout = tsk("pima")
splits = partition(task, 0.7)
task$filter(splits$train)
task_holdout$filter(splits$test)
callback$state$task = task_holdout
rr = resample(task, learner, resampling, callbacks = callback)
rr$data_extra
Run the code above in your browser using DataLab