Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
sebffischer committed Oct 28, 2024
1 parent d7e2f23 commit a9a9195
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 10 additions & 4 deletions book/chapters/chapter15/predsets_valid_inttune.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ ggplot(data = d, aes(x = eta, y = nrounds, color = logloss)) +
geom_point() + theme_minimal()
```

This also works with an `r ref("AutoTuner")`, which will use the internally optimized `nrounds`, as well as the offline tuned `eta` for the final model fit. This means that there is no validation or early stopping when training the final model, and we use as much data as possible.
This also works with an `r ref("AutoTuner")`, which will use the internally optimized `nrounds`, as well as the offline tuned `eta` for the final model fit.
This means that there is no validation or early stopping when training the final model, and we use as much data as possible.

```{r}
at = auto_tuner(
Expand All @@ -330,9 +331,13 @@ at = auto_tuner(
at$train(tsk_sonar)
```

If we were to resample the `AutoTuner` from above, we would still get valid performance estimates. This is because the test set of the outer resampling is *never* used as validation data, since the final model fit does not perform any validation. The validation data generated during the hyperparameter tuning uses the test set of the inner resampling, which is a subset of the training set of the outer resampling.
If we were to resample the `AutoTuner` from above, we would still get valid performance estimates.
This is because the test set of the outer resampling is *never* used as validation data, since the final model fit does not perform any validation.
The validation data generated during the hyperparameter tuning uses the test set of the inner resampling, which is a subset of the training set of the outer resampling.

However, care must be taken when using the test set of a resampling for validation. Whether this is OK depends on the context and purpose of the resampling. If the purpose of resampling is to get an unbiased performance estimate of algorithms, some of which stop early and some of which don't, this is not OK. In such a situation, the former would have an unfair advantage over the latter. The example below illustrates such a case where this would not be a fair comparison between the two learners.
However, care must be taken when using the test set of a resampling for validation. Whether this is OK depends on the context and purpose of the resampling.
If the purpose of resampling is to get an unbiased performance estimate of algorithms, some of which stop early and some of which don't, this is not OK.
In such a situation, the former would have an unfair advantage over the latter. The example below illustrates such a case where this would not be a fair comparison between the two learners.

```{r}
lrn_xgb$param_set$set_values(
Expand All @@ -347,7 +352,8 @@ bmr = benchmark(design)
bmr$aggregate(msr("classif.ce"))
```

At last, we will cover how to enable internal tuning when manually specifying a search space with the `ps()` function instead of the `to_tune()`-mechanism. While the latter is more convenient and therefore usually recommended, manually defining a search space gives you for more flexibility with respect to parameter transformations, see e.g. @sec-tune-trafo. Below, we define the search space from the previous example. To mark the `nrounds` parameter for internal tuning we have to tag it with `"internal_tuning"` and specify the aggregation function, in this case to take the average number of rounds across the folds.
At last, we will cover how to enable internal tuning when manually specifying a search space with the `ps()` function instead of the `to_tune()`-mechanism.
While the latter is more convenient and therefore usually recommended, manually defining a search space gives you for more flexibility with respect to parameter transformations, see e.g. @sec-tune-trafo. Below, we define the search space from the previous example. To mark the `nrounds` parameter for internal tuning we have to tag it with `"internal_tuning"` and specify the aggregation function, in this case to take the average number of rounds across the folds.

```{r}
search_space = ps(
Expand Down
10 changes: 8 additions & 2 deletions book/renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3874,8 +3874,14 @@
},
"mlr3tuning": {
"Package": "mlr3tuning",
"Version": "1.1.0",
"Source": "Repository"
"Version": "1.1.0.9000",
"Source": "GitHub",
"RemoteType": "github",
"RemoteHost": "api.github.com",
"RemoteUsername": "mlr-org",
"RemoteRepo": "mlr3tuning",
"RemoteRef": "main",
"RemoteSha": "61802edaba88dd3051b9148e5aaa2b1aa43c818f"
},
"mlr3tuningspaces": {
"Package": "mlr3tuningspaces",
Expand Down

0 comments on commit a9a9195

Please sign in to comment.