Parameter Tuning of Functions Using Grid Search

DESCRIPTION:

This generic function tunes hyperparameters of statistical methods using a grid search over supplied parameter ranges.

USAGE:

tune(method, train.x, train.y=NULL, data=list(), validation.x= NULL,
     validation.y=NULL, ranges=NULL, predict.func=predict,
     tunecontrol=tune.control(), ...)
best.tune(...)

ARGUMENTS:

method
function to be tuned.
train.x
either a formula or a matrix of predictors.
train.y
the response variable if train.x is a predictor matrix. Ignored if train.x is a formula.
data
data, if a formula interface is used. Ignored, if predictor matrix and response are supplied directly.
validation.x
an optional validation set. Depending on whether a formula interface is used or not, the response can be included in validation.x or separately specified using validation.y.
validation.y
if no formula interface is used, the response of the (optional) validation set.
ranges
a named list of parameter vectors spanning the sampling space. The vectors will usually be created by seq.
predict.func
optional predict function, if the standard predict behaviour is inadequate.
tunecontrol
object of class "tune.control", as created by the function tune.control(). If omitted, tune.control() gives the defaults.
...
Further parameters passed to the training functions.

DETAILS:

As performance measure, the classification error is used for classification, and the mean squared error for regression. It is possible to specify only one parameter combination (i.e., vectors of length 1) to obtain an error estimation of the specified type (bootstrap, cross-classification, etc.) on the given data set. For conveneince, there are tune.foo() wrappers defined for svm().

Cross-validation randomizes the data set before building the splits which, once created, remain constant during the training process. The splits can be recovered through the train.ind component of the returned object.

VALUE:

For tune, an object of class tune, including the components:
best.parameters
a 1 x k data frame, k number of parameters.
best.performance
best achieved performance.
performances
if requested, a data frame of all parameter combinations along with the corresponding performance results.
train.ind
list of index vectors used for splits into training and validation sets.
best.model
if requested, the model trained on the complete training data using the best parameter combination.

best.tune() returns the best model detected by tune.

AUTHOR(S):

David Meyer
mailto:David.Meyer@R-project.org

SEE ALSO:

, , ,

EXAMPLES:

  ## tune `svm' for classification with RBF-kernel (default in svm),
  ## using one split for training/validation set
  
  
  obj <- tune(svm, Species~., data = iris.df, 
              ranges = list(gamma = 2^(-1:1), cost = 2^(2:4)),
              tunecontrol = tune.control(sampling = "fix")
             )

  ## alternatively:
  obj <- tune.svm(Species~., data = iris.df, gamma = 2^(-1:1),
                     cost = 2^(2:4))

  summary(obj)
#  plot(obj)