Recently I was learning about using mlr3 package. I was doing a feature selection and wanted to compare the model results.However, I wonder how to get the model results from a Benchmarkresult, like what features were uesd in the feature selected learner model.
Here is my code:
#setup task
task = TaskClassif$new(id = "SPI", backend = test, target = "recidivism")
#learner of non-FS
learner_ranger = lrn("classif.ranger",
predict_type = "prob",
predict_sets = c("train", "test")) %>% print()
# set up for FS
terminator = trm("evals", n_evals = 20)
fselector = fs("random_search")
# create a new learner of FS
at = AutoFSelector$new(
learner = learner_ranger,
resampling = rsmp("holdout"),
measure = msr("classif.auc"),
terminator = terminator,
fselector = fselector
)
at
# To compare the optimized feature subset with the complete feature set, we can use benchmark() :
grid = benchmark_grid(task = task,
learner = list(at,learner_ranger),
resampling = rsmp("holdout"))
#
set.seed(1)
bmr_Wra = benchmark(grid, store_models = TRUE)
#
measures = list(
msr("classif.auc", id = "auc_train", predict_sets = "train"),
msr("classif.auc", id = "auc_test"),
msr("classif.acc", id = "acc_test"),
msr("classif.ce",id = "ce_test")
)
bmr_Wra$aggregate(measures)
# ce
autoplot(bmr_Wra) + theme(axis.text.x = element_text(angle = 45, hjust = 1))
# roc
autoplot(bmr_Wra, type = "roc")
# prc
autoplot(bmr_Wra, type = "prc")`
I noticed that :
Note that it is not feasible to access learned models via this field, as the training task would be ambiguous. For this reason the returned learner are reseted before they are returned. Instead, select a row from the table returned by $score().
So I uesd bmr_Wra$score()
, but I still need to further analyse the models and extract information like variable importance. Any help is appreciated. Thanks a lot!