knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
finetune
contains some extra functions for model tuning that extend what is currently in the tune
package. You can install the CRAN version of the package with the following code:
install.packages("finetune")
To install the development version of the package, run:
# install.packages("pak") pak::pak("tidymodels/finetune")
There are two main sets of tools in the package: simulated annealing and racing.
Tuning via simulated annealing optimization is an iterative search tool for finding good values:
library(tidymodels) library(finetune) library(discrim) library(rlang) library(MASS)
library(tidymodels) library(finetune) # Syntax very similar to `tune_grid()` or `tune_bayes()`: ## ----------------------------------------------------------------------------- data(two_class_dat, package = "modeldata") set.seed(1) rs <- bootstraps(two_class_dat, times = 10) # more resamples usually needed # Optimize a regularized discriminant analysis model library(discrim) rda_spec <- discrim_regularized(frac_common_cov = tune(), frac_identity = tune()) %>% set_engine("klaR") ## ----------------------------------------------------------------------------- set.seed(2) sa_res <- rda_spec %>% tune_sim_anneal(Class ~ ., resamples = rs, iter = 20, initial = 4) show_best(sa_res, metric = "roc_auc", n = 2)
The second set of methods are for racing. We start off by doing a small set of resamples for all of the grid points, then statistically testing to see which ones should be dropped or investigated more. The two methods here are based on those should in Kuhn (2014).
For example, using an ANOVA-type analysis to filter out parameter combinations:
set.seed(3) grid <- rda_spec %>% extract_parameter_set_dials() %>% grid_max_entropy(size = 20) ctrl <- control_race(verbose_elim = TRUE) set.seed(4) grid_anova <- rda_spec %>% tune_race_anova(Class ~ ., resamples = rs, grid = grid, control = ctrl) show_best(grid_anova, metric = "roc_auc", n = 2)
tune_race_win_loss()
can also be used. It treats the tuning parameters as sports teams in a tournament and computed win/loss statistics.
set.seed(4) grid_win_loss<- rda_spec %>% tune_race_win_loss(Class ~ ., resamples = rs, grid = grid, control = ctrl) show_best(grid_win_loss, metric = "roc_auc", n = 2)
This project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
For questions and discussions about tidymodels packages, modeling, and machine learning, please post on Posit Community.
If you think you have encountered a bug, please submit an issue.
Either way, learn how to create and share a reprex (a minimal, reproducible example), to clearly communicate about your code.
Check out further details on contributing guidelines for tidymodels packages and how to get help.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.