This CallbackResample extracts information from the model after training with a user-defined function.
This way information can be extracted from the model without saving the model (store_models = FALSE
).
The fun
must be a function that takes a learner as input and returns the extracted information as named list (see example).
The callback is very helpful to call $selected_features()
, $importance()
, $oob_error()
on the learner.
Examples
task = tsk("pima")
learner = lrn("classif.rpart")
resampling = rsmp("cv", folds = 3)
# define function to extract selected features
selected_features = function(learner) list(selected_features = learner$selected_features())
# create callback
callback = clbk("mlr3.model_extractor", fun = selected_features)
rr = resample(task, learner, resampling = resampling, store_models = FALSE, callbacks = callback)
rr$data_extra
#> Key: <uhash, iteration>
#> uhash iteration data_extra
#> <char> <int> <list>
#> 1: 7b434a39-2aae-471c-bd1e-3e560a5ca256 1 <list[1]>
#> 2: 7b434a39-2aae-471c-bd1e-3e560a5ca256 2 <list[1]>
#> 3: 7b434a39-2aae-471c-bd1e-3e560a5ca256 3 <list[1]>