# Automatic Tuning
# split to train and external set
task = tsk("penguins")
split = partition(task, ratio = 0.8)
# load learner and set search space
learner = lrn("classif.rpart",
cp = to_tune(1e-04, 1e-1, logscale = TRUE)
)
# create auto tuner
at = auto_tuner(
tuner = tnr("random_search"),
learner = learner,
resampling = rsmp ("holdout"),
measure = msr("classif.ce"),
term_evals = 4)
# tune hyperparameters and fit final model
at$train(task, row_ids = split$train)
# predict with final model
at$predict(task, row_ids = split$test)
# show tuning result
at$tuning_result
# model slot contains trained learner and tuning instance
at$model
# shortcut trained learner
at$learner
# shortcut tuning instance
at$tuning_instance
# Nested Resampling
at = auto_tuner(
tuner = tnr("random_search"),
learner = learner,
resampling = rsmp ("holdout"),
measure = msr("classif.ce"),
term_evals = 4)
resampling_outer = rsmp("cv", folds = 3)
rr = resample(task, at, resampling_outer, store_models = TRUE)
# retrieve inner tuning results.
extract_inner_tuning_results(rr)
# performance scores estimated on the outer resampling
rr$score()
# unbiased performance of the final model trained on the full data set
rr$aggregate()
Run the code above in your browser using DataLab