Function to construct a TuningInstanceBatchSingleCrit or TuningInstanceBatchMultiCrit.
Usage
ti(
task,
learner,
resampling,
measures = NULL,
terminator,
search_space = NULL,
internal_search_space = NULL,
store_benchmark_result = TRUE,
store_models = FALSE,
check_values = FALSE,
callbacks = NULL
)
Arguments
- task
(mlr3::Task)
Task to operate on.- learner
(mlr3::Learner)
Learner to tune.- resampling
(mlr3::Resampling)
Resampling that is used to evaluate the performance of the hyperparameter configurations. Uninstantiated resamplings are instantiated during construction so that all configurations are evaluated on the same data splits. Already instantiated resamplings are kept unchanged. Specialized Tuner change the resampling e.g. to evaluate a hyperparameter configuration on different data splits. This field, however, always returns the resampling passed in construction.- measures
(mlr3::Measure or list of mlr3::Measure)
A single measure creates a TuningInstanceBatchSingleCrit and multiple measures a TuningInstanceBatchMultiCrit. IfNULL
, default measure is used.- terminator
(bbotk::Terminator)
Stop criterion of the tuning process.- search_space
(paradox::ParamSet)
Hyperparameter search space. IfNULL
(default), the search space is constructed from the paradox::TuneToken of the learner's parameter set (learner$param_set).- internal_search_space
(paradox::ParamSet or
NULL
)
The internal search space.- store_benchmark_result
(
logical(1)
)
IfTRUE
(default), store resample result of evaluated hyperparameter configurations in archive as mlr3::BenchmarkResult.- store_models
(
logical(1)
)
IfTRUE
, fitted models are stored in the benchmark result (archive$benchmark_result
). Ifstore_benchmark_result = FALSE
, models are only stored temporarily and not accessible after the tuning. This combination is needed for measures that require a model.- check_values
(
logical(1)
)
IfTRUE
, hyperparameter values are checked before evaluation and performance scores after. IfFALSE
(default), values are unchecked but computational overhead is reduced.- callbacks
(list of mlr3misc::Callback)
List of callbacks.
Resources
There are several sections about hyperparameter optimization in the mlr3book.
Getting started with hyperparameter optimization.
An overview of all tuners can be found on our website.
Tune a support vector machine on the Sonar data set.
Learn about tuning spaces.
Estimate the model performance with nested resampling.
Learn about multi-objective optimization.
Simultaneously optimize hyperparameters and use early stopping with XGBoost.
Automate the tuning.
The gallery features a collection of case studies and demos about optimization.
Learn more advanced methods with the Practical Tuning Series.
Learn about hotstarting models.
Run the default hyperparameter configuration of learners as a baseline.
Use the Hyperband optimizer with different budget parameters.
The cheatsheet summarizes the most important functions of mlr3tuning.
Default Measures
If no measure is passed, the default measure is used. The default measure depends on the task type.
Task | Default Measure | Package |
"classif" | "classif.ce" | mlr3 |
"regr" | "regr.mse" | mlr3 |
"surv" | "surv.cindex" | mlr3proba |
"dens" | "dens.logloss" | mlr3proba |
"classif_st" | "classif.ce" | mlr3spatial |
"regr_st" | "regr.mse" | mlr3spatial |
"clust" | "clust.dunn" | mlr3cluster |
Examples
# Hyperparameter optimization on the Palmer Penguins data set
task = tsk("penguins")
# Load learner and set search space
learner = lrn("classif.rpart",
cp = to_tune(1e-04, 1e-1, logscale = TRUE)
)
# Construct tuning instance
instance = ti(
task = task,
learner = learner,
resampling = rsmp("cv", folds = 3),
measures = msr("classif.ce"),
terminator = trm("evals", n_evals = 4)
)
# Choose optimization algorithm
tuner = tnr("random_search", batch_size = 2)
# Run tuning
tuner$optimize(instance)
#> cp learner_param_vals x_domain classif.ce
#> <num> <list> <list> <num>
#> 1: -8.460007 <list[2]> <list[1]> 0.04942792
# Set optimal hyperparameter configuration to learner
learner$param_set$values = instance$result_learner_param_vals
# Train the learner on the full data set
learner$train(task)
# Inspect all evaluated configurations
as.data.table(instance$archive)
#> cp classif.ce runtime_learners timestamp warnings errors
#> <num> <num> <num> <POSc> <int> <int>
#> 1: -3.372665 0.05814900 0.017 2024-11-08 15:18:05 0 0
#> 2: -3.054465 0.05814900 0.016 2024-11-08 15:18:05 0 0
#> 3: -8.460007 0.04942792 0.016 2024-11-08 15:18:05 0 0
#> 4: -4.158236 0.05814900 0.016 2024-11-08 15:18:05 0 0
#> x_domain batch_nr resample_result
#> <list> <int> <list>
#> 1: <list[1]> 1 <ResampleResult>
#> 2: <list[1]> 1 <ResampleResult>
#> 3: <list[1]> 2 <ResampleResult>
#> 4: <list[1]> 2 <ResampleResult>