-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
123 lines (94 loc) · 4 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
output: github_document
bibliography: references.bib
---
```{r, include = FALSE}
library(mlr3misc)
library(utils)
library(mlr3tuningspaces)
library(data.table)
source("R/bibentries.R")
writeLines(toBibtex(bibentries), "references.bib")
lgr::get_logger("mlr3")$set_threshold("warn")
lgr::get_logger("bbotk")$set_threshold("warn")
set.seed(0)
options(
datatable.print.nrows = 10,
datatable.print.class = FALSE,
datatable.print.keys = FALSE,
datatable.print.trunc.cols = TRUE,
width = 100)
# mute load messages
library(bbotk)
library(mlr3verse)
library(mlr3hyperband)
library(mlr3learners)
```
# mlr3hyperband <img src="man/figures/logo.png" align="right" width = "120" />
Package website: [release](https://mlr3hyperband.mlr-org.com/) | [dev](https://mlr3hyperband.mlr-org.com/dev/)
<!-- badges: start -->
[![r-cmd-check](https://github.com/mlr-org/mlr3hyperband/actions/workflows/r-cmd-check.yml/badge.svg)](https://github.com/mlr-org/mlr3hyperband/actions/workflows/r-cmd-check.yml)
[![CRAN Status](https://www.r-pkg.org/badges/version-ago/mlr3hyperband)](https://cran.r-project.org/package=mlr3hyperband)
[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)
[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)
<!-- badges: end -->
*mlr3hyperband* adds the optimization algorithms Successive Halving [@jamieson_2016] and Hyperband [@li_2018] to the [mlr3](https://mlr-org.com/) ecosystem.
The implementation in mlr3hyperband features improved scheduling and parallelizes the evaluation of configurations.
The package includes tuners for hyperparameter optimization in [mlr3tuning](https://github.com/mlr-org/mlr3tuning) and optimizers for black-box optimization in [bbotk](https://github.com/mlr-org/bbotk).
## Resources
There are several sections about hyperparameter optimization in the [mlr3book](https://mlr3book.mlr-org.com).
The [gallery](https://mlr-org.com/gallery.html) features a series of case studies on Hyperband.
* [Tune](https://mlr-org.com/gallery/series/2023-01-15-hyperband-xgboost/) the hyperparameters of XGBoost with Hyperband
* Use data [subsampling](https://mlr-org.com/gallery/series/2023-01-16-hyperband-subsampling/) and Hyperband to optimize a support vector machine.
## Installation
Install the last release from CRAN:
```{r, eval = FALSE}
install.packages("mlr3hyperband")
```
Install the development version from GitHub:
```{r, eval = FALSE}
remotes::install_github("mlr-org/mlr3hyperband")
```
## Examples
We optimize the hyperparameters of an XGBoost model on the [Sonar](https://mlr3.mlr-org.com/reference/mlr_tasks_sonar.html) data set.
The number of boosting rounds `nrounds` is the fidelity parameter.
We tag this parameter with `"budget"` in the search space.
```{r}
library(mlr3hyperband)
library(mlr3learners)
learner = lrn("classif.xgboost",
nrounds = to_tune(p_int(27, 243, tags = "budget")),
eta = to_tune(1e-4, 1, logscale = TRUE),
max_depth = to_tune(1, 20),
colsample_bytree = to_tune(1e-1, 1),
colsample_bylevel = to_tune(1e-1, 1),
lambda = to_tune(1e-3, 1e3, logscale = TRUE),
alpha = to_tune(1e-3, 1e3, logscale = TRUE),
subsample = to_tune(1e-1, 1)
)
```
We use the `tune()` function to run the optimization.
```{r}
instance = tune(
tnr("hyperband", eta = 3),
task = tsk("pima"),
learner = learner,
resampling = rsmp("cv", folds = 3),
measures = msr("classif.ce")
)
```
The instance contains the best-performing hyperparameter configuration.
```{r}
instance$result
```
The archive contains all evaluated hyperparameter configurations.
Hyperband adds the `"stage"` and `"braket"`.
```{r}
as.data.table(instance$archive)[, .(stage, bracket, classif.ce, nrounds)]
```
We fit a final model with optimized hyperparameters to make predictions on new data.
```{r}
learner$param_set$values = instance$result_learner_param_vals
learner$train(tsk("sonar"))
```
## References