Skip to content

Commit d788050

Browse files
committed
docs: readme
1 parent 065dcc7 commit d788050

File tree

2 files changed

+119
-193
lines changed

2 files changed

+119
-193
lines changed

README.Rmd

Lines changed: 56 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ output: github_document
33
---
44

55
```{r, include = FALSE}
6-
lgr::get_logger("mlr3")$set_threshold("warn")
7-
lgr::get_logger("bbotk")$set_threshold("warn")
6+
lgr::get_logger("mlr3")$set_threshold("error")
7+
lgr::get_logger("bbotk")$set_threshold("error")
88
set.seed(1)
99
options(datatable.print.class = FALSE, datatable.print.keys = FALSE, width = 200)
1010
```
@@ -20,7 +20,19 @@ Package website: [release](https://mlr3hyperband.mlr-org.com/) | [dev](https://m
2020
[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)
2121
<!-- badges: end -->
2222

23-
This package provides hyperband tuning for [`mlr3`](https://mlr3.mlr-org.com).
23+
`mlr3hyperband` extends the [mlr3tuning](https://mlr3tuning.mlr-org.com/) package with multifidelity optimization methods based on the successive halving algorithm.
24+
It currently provides the following optimizers for [bbotk](https://bbotk.mlr-org.com/) and tuner for [mlr3tuning](https://mlr3tuning.mlr-org.com/):
25+
26+
* Successive Halving (`OptimizerSuccessiveHalving` & `TunerSuccessiveHalving`)
27+
* Hyperband (`OptimizerSuccessiveHalving` & `TunerSuccessiveHalving`)
28+
29+
## Resources
30+
31+
* mlr3book chapter on [hyperband](https://mlr3book.mlr-org.com/optimization.html#hyperband)
32+
and [hyperparameter tuning](https://mlr3book.mlr-org.com/optimization.html#tuning).
33+
* The original publications introducing the [successive halving](https://arxiv.org/abs/1502.07943) and
34+
[hyperband](https://arxiv.org/abs/1603.06560).
35+
* Ask questions on [Stackoverflow (tag #mlr3)](https://stackoverflow.com/questions/tagged/mlr3)
2436

2537
## Installation
2638

@@ -36,26 +48,10 @@ Install the development version from GitHub:
3648
remotes::install_github("mlr-org/mlr3hyperband")
3749
```
3850

39-
## Resources
40-
41-
* mlr3book chapter on [hyperband](https://mlr3book.mlr-org.com/optimization.html#hyperband)
42-
and [hyperparameter tuning](https://mlr3book.mlr-org.com/optimization.html#tuning).
43-
* The original [paper](https://arxiv.org/abs/1603.06560) introducing the hyperband algorithm.
44-
45-
## Hyperband
46-
47-
Hyperband is a budget oriented-procedure, weeding out suboptimally performing configurations early on during their training process aiming at increasing the efficiency of the tuning procedure.
48-
For this, several brackets are constructed with an associated set of configurations for each bracket.
49-
These configuration are initialized by stochastic, often uniform, sampling.
50-
Each bracket is divided into multiple stages, and configurations are evaluated for a increasing budget in each stage.
51-
Note that currently all configurations are trained completely from the beginning, so no online updates to the models are performed.
52-
53-
Different brackets are initialized with different number of configurations, and different budget sizes.
54-
To identify the budget for evaluating hyperband, the user has to specify explicitly which hyperparameter of the learner influences the budget by tagging a single hyperparameter in the parameter set with `"budget"`.
55-
An alternative approach using subsampling and pipelines is described further below.
56-
5751
## Examples
5852

53+
### Basic
54+
5955
```{r, include = FALSE}
6056
# mute load messages
6157
library(bbotk)
@@ -64,53 +60,24 @@ library(mlr3hyperband)
6460
library(mlr3learners)
6561
```
6662

67-
### Basic
68-
69-
If you are already familiar with `mlr3tuning`, then the only change compared to other tuners is to give a numeric hyperparameter a `budget` tag.
70-
Afterwards, you can handle hyperband like all other tuners.
71-
Originally, hyperband was created with a “natural” learning parameter as the budget parameter in mind, like `nrounds` of the XGBoost learner.
72-
7363
```{r}
74-
library(mlr3verse)
7564
library(mlr3hyperband)
7665
library(mlr3learners)
7766
78-
# define hyperparameter and budget parameter
79-
search_space = ps(
80-
nrounds = p_int(lower = 1, upper = 16, tags = "budget"),
81-
eta = p_dbl(lower = 0, upper = 1),
82-
booster = p_fct(levels = c("gbtree", "gblinear", "dart"))
67+
# load learner, define search space and tag budget hyperparameter
68+
learner = lrn("classif.xgboost",
69+
nrounds = to_tune(p_int(27, 243, tags = "budget")),
70+
eta = to_tune(1e-4, 1, logscale = TRUE),
71+
max_depth = to_tune(1, 20),
72+
colsample_bytree = to_tune(1e-1, 1),
73+
colsample_bylevel = to_tune(1e-1, 1),
74+
lambda = to_tune(1e-3, 1e3, logscale = TRUE),
75+
alpha = to_tune(1e-3, 1e3, logscale = TRUE),
76+
subsample = to_tune(1e-1, 1)
8377
)
8478
85-
# hyperparameter tuning on the pima indians diabetes data set
86-
instance = tune(
87-
method = "hyperband",
88-
task = tsk("pima"),
89-
learner = lrn("classif.xgboost", eval_metric = "logloss"),
90-
resampling = rsmp("cv", folds = 3),
91-
measures = msr("classif.ce"),
92-
search_space = search_space
93-
)
94-
95-
# best performing hyperparameter configuration
96-
instance$result
97-
```
98-
99-
### Subsampling
100-
101-
Additionally, it is also possible to use `mlr3hyperband` to tune learners that do not have a natural fidelity parameter.
102-
In such a case `mlr3pipelines` can be used to define data subsampling as a preprocessing step.
103-
Then, the `frac` parameter of subsampling, defining the fraction of the training data to be used, can act as the budget parameter.
104-
105-
```{r}
106-
learner = po("subsample") %>>% lrn("classif.rpart")
107-
108-
# define subsampling parameter as budget
109-
search_space = ps(
110-
classif.rpart.cp = p_dbl(lower = 0.001, upper = 0.1),
111-
classif.rpart.minsplit = p_int(lower = 1, upper = 10),
112-
subsample.frac = p_dbl(lower = 0.1, upper = 1, tags = "budget")
113-
)
79+
# set parallel backend
80+
future::plan("multisession")
11481
11582
# hyperparameter tuning on the pima indians diabetes data set
11683
instance = tune(
@@ -119,38 +86,42 @@ instance = tune(
11986
learner = learner,
12087
resampling = rsmp("cv", folds = 3),
12188
measures = msr("classif.ce"),
122-
search_space = search_space
89+
eta = 3
12390
)
124-
125-
# best performing hyperparameter configuration
126-
instance$result
12791
```
12892

129-
### Successive Halving
93+
### Subsample
13094

131-
```{r, message = FALSE}
95+
```{r}
13296
library(mlr3hyperband)
13397
library(mlr3learners)
98+
library(mlr3pipelines)
13499
135-
# define hyperparameter and budget parameter
136-
search_space = ps(
137-
nrounds = p_int(lower = 1, upper = 16, tags = "budget"),
138-
eta = p_dbl(lower = 0, upper = 1),
139-
booster = p_fct(levels = c("gbtree", "gblinear", "dart"))
100+
# load learner and define search space
101+
learner = lrn("classif.rpart",
102+
minsplit = to_tune(2, 128, logscale = TRUE),
103+
minbucket = to_tune(1, 64, logscale = TRUE),
104+
cp = to_tune(1e-04, 1e-1, logscale = TRUE)
140105
)
141106
142-
# hyperparameter tuning on the pima indians diabetes data set
107+
# create graph learner with subsampling
108+
graph_learner = as_learner(po("subsample") %>>% learner)
109+
110+
# tag budget parameter
111+
graph_learner$param_set$values$subsample.frac = to_tune(p_dbl(3^-3, 1, tags = "budget"))
112+
113+
# set parallel backend
114+
future::plan("multisession")
115+
116+
# hyperparameter tuning on the spam data set
143117
instance = tune(
144-
method = "successive_halving",
145-
task = tsk("pima"),
146-
learner = lrn("classif.xgboost", eval_metric = "logloss"),
118+
method = "hyperband",
119+
task = tsk("spam"),
120+
learner = graph_learner,
147121
resampling = rsmp("cv", folds = 3),
148122
measures = msr("classif.ce"),
149-
search_space = search_space
123+
eta = 3
150124
)
151-
152-
# best performing hyperparameter configuration
153-
instance$result
154125
```
155126

156127
### Quick general-purpose optimization
@@ -161,9 +132,9 @@ library(mlr3hyperband)
161132
162133
# define hyperparameter and budget parameter
163134
search_space = domain = ps(
164-
x1 = p_dbl(-5, 10),
165-
x2 = p_dbl(0, 15),
166-
fidelity = p_dbl(1e-2, 1, tags = "budget")
135+
x1 = p_dbl(-5, 10),
136+
x2 = p_dbl(0, 15),
137+
fidelity = p_dbl(1e-2, 1, tags = "budget")
167138
)
168139
169140
# modified branin function
@@ -174,7 +145,7 @@ objective = ObjectiveRFun$new(
174145
)
175146
176147
# optimize branin function with hyperband
177-
result = bb_optimize(objective, method = "hyperband", search_space = search_space, term_evals = NULL)
148+
result = bb_optimize(objective, method = "hyperband", search_space = search_space, term_evals = NULL, eta = 2)
178149
179150
# optimized parameters
180151
result$par

0 commit comments

Comments
 (0)