gridCV: Perform a grid search for the provided tuning parameters...

View source: R/gridCV.r

gridCVR Documentation

Perform a grid search for the provided tuning parameters using k-fold cross validation

Description

For a given method, the values will be tuned systematically by iterating through each of the values provided in the model$tune.parameters and compared to all of the other model$tune.parameters. The hyper parameters are the tuning parameter values with the highest error value.

Usage

gridCV(data, predictor, model, folds = 10)

Arguments

data

Input to the model in a data frame format

predictor

A string of the vector of the validation set that contains the true values of the dependent variable.

folds

The number of folds in the cross validation method. Default is 10.

method

The function call used to learn the model

model$method.parameters

Additional parameters passed through to the method to learn the model. This should not include parameters that are going to be predicted.

model$tune.parameters

Parameters that will be predicted based on the cross- validation error. This should be passed through as a list with each of the objects equal to an array of values to test.

model$pred.parameters

Parameters required to use the predict function on the method type. There is no need to pass values for the model or the data, they are already provided.

Value

A list with the values of the hyper parameters stored as the parameter object. Also the overall cross-validated error is reported as the error object. And all of the grid values and their errors are reported as the tune.grid object.

See Also

caret::train()

Examples

svm.radial.hyper <- gridCV(
   method = svm, model$method.parameters = list(kernel="radial"), folds = 4,
   data = weather.train, predictor = "RainTomorrow", 
   tune = list("gamma" = 10^(1:3), "cost" = 10^(-1:0))
   )

## [1] "Tuning..."
##     gamma      cost  error 
## 0.1000000 0.1000000 0.8309324 
##    gamma     cost error 
##     1.00     0.10     0.78 
##    gamma     cost error 
##    10.00     0.10     0.78 
##    gamma     cost error 
##   100.00     0.10     0.78 
##    gamma     cost error 
##  1000.00     0.10     0.78 
##    gamma     cost error 
## 0.100000 1.000000 0.852933 
##    gamma     cost error 
##     1.00     1.00     0.78 
##    gamma     cost error 
##    10.00     1.00     0.78 
##    gamma     cost error 
##   100.00     1.00     0.78 
##    gamma     cost error 
##  1000.00     1.00     0.78 

joshuaderekwhite/buildmodels documentation built on April 27, 2022, 3:35 a.m.