Learn R Programming

MachineShop (version 1.6.0)

tune: Model Tuning and Selection

Description

Predictive peformance-based tuning of a model over a grid of parameters values or selection from a set of candidate models.

Usage

tune(x, ...)

# S3 method for formula tune(x, data, models, grid = MachineShop::settings("grid"), fixed = NULL, control = MachineShop::settings("control"), metrics = NULL, stat = MachineShop::settings("stat.Tune"), ...)

# S3 method for matrix tune(x, y, models, grid = MachineShop::settings("grid"), fixed = NULL, control = MachineShop::settings("control"), metrics = NULL, stat = MachineShop::settings("stat.Tune"), ...)

# S3 method for ModelFrame tune(x, models, grid = MachineShop::settings("grid"), fixed = NULL, control = MachineShop::settings("control"), metrics = NULL, stat = MachineShop::settings("stat.Tune"), ...)

# S3 method for recipe tune(x, models, grid = MachineShop::settings("grid"), fixed = NULL, control = MachineShop::settings("control"), metrics = NULL, stat = MachineShop::settings("stat.Tune"), ...)

# S3 method for MLModel tune(x, ...)

# S3 method for MLModelFunction tune(x, ...)

# S3 method for MLModelList tune(x, ...)

Arguments

x

defines a relationship between model predictor and response variables. May be a formula, design matrix of predictors, ModelFrame, untrained recipe, or TunedRecipe object. Alternatively, a model function, call, or list of these may be given first followed by objects defining the predictor and response relationship and the other tuning argument values.

...

arguments passed to the performance functions.

data

data frame containing observed predictors and outcomes.

models

model function, function name, or call defining a model to tune; or vector of these from which to select, such as that returned by expand_model.

grid

data frame containing parameter values at which to evaluate a single model supplied to models, such as that returned by expand_params; the number of parameter-specific values to generate automatically if the model has a pre-defined grid; or a call to Grid. Ignored in the case of a list of models.

fixed

list of fixed parameter values to combine with those in grid.

control

control function, function name, or call defining the resampling method to be employed.

metrics

metric function, function name, or vector of these with which to calculate performance. If not specified, default metrics defined in the performance functions are used. Model selection is based on the first calculated metric.

stat

function or character string naming a function to compute a summary statistic on resampled metric values for model tuning.

y

response variable.

Value

MLModelTune class object that inherits from MLModel.

See Also

fit, performance, metrics, plot, summary

Examples

Run this code
# NOT RUN {
## Numeric response example
fo <- sale_amount ~ .

# User-specified grid
(gbm_tune1 <- tune(fo, data = ICHomes, model = GBMModel,
                   grid = expand_params(n.trees = c(25, 50, 100),
                                        interaction.depth = 1:3,
                                        n.minobsinnode = c(5, 10)),
                   control = CVControl(folds = 10, repeats = 5)))

# Automatically generated grid
(gbm_tune2 <- tune(fo, data = ICHomes, model = GBMModel, grid = 3,
                   control = CVControl(folds = 10, repeats = 5)))

# Randomly sampled grid points
(gbm_tune3 <- tune(fo, data = ICHomes, model = GBMModel,
                   grid = Grid(length = 1000, random = 10),
                   control = CVControl(folds = 10, repeats = 5)))

summary(gbm_tune1)
plot(gbm_tune1, type = "line")

gbm_fit <- fit(fo, data = ICHomes, model = gbm_tune1)
varimp(gbm_fit)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab