tune_cluster {tidyclust} | R Documentation |
Model tuning via grid search
Description
tune_cluster()
computes a set of performance metrics (e.g. accuracy or
RMSE) for a pre-defined set of tuning parameters that correspond to a model
or recipe across one or more resamples of the data.
Usage
tune_cluster(object, ...)
## S3 method for class 'cluster_spec'
tune_cluster(
object,
preprocessor,
resamples,
...,
param_info = NULL,
grid = 10,
metrics = NULL,
control = tune::control_grid()
)
## S3 method for class 'workflow'
tune_cluster(
object,
resamples,
...,
param_info = NULL,
grid = 10,
metrics = NULL,
control = tune::control_grid()
)
Arguments
object |
A |
... |
Not currently used. |
preprocessor |
A traditional model formula or a recipe created using
|
resamples |
An |
param_info |
A |
grid |
A data frame of tuning combinations or a positive integer. The data frame should have columns for each parameter being tuned and rows for tuning parameter candidates. An integer denotes the number of candidate parameter sets to be created automatically. |
metrics |
A |
control |
An object used to modify the tuning process. Defaults to
|
Value
An updated version of resamples
with extra list columns for
.metrics
and .notes
(optional columns are .predictions
and
.extracts
). .notes
contains warnings and errors that occur during
execution.
Examples
library(recipes)
library(rsample)
library(workflows)
library(tune)
rec_spec <- recipe(~., data = mtcars) %>%
step_normalize(all_numeric_predictors()) %>%
step_pca(all_numeric_predictors())
kmeans_spec <- k_means(num_clusters = tune())
wflow <- workflow() %>%
add_recipe(rec_spec) %>%
add_model(kmeans_spec)
grid <- tibble(num_clusters = 1:3)
set.seed(4400)
folds <- vfold_cv(mtcars, v = 2)
res <- tune_cluster(
wflow,
resamples = folds,
grid = grid
)
res
collect_metrics(res)