caretModels: Build a caret model

Description Usage Arguments Examples

View source: R/caretModels.R

Description

A function to build prediction models for the training set.

Usage

1
2
3
4
5
6
7
8
9
caretModels(
  TrainSet,
  resp.var,
  trControl,
  preProcess,
  tuneLength,
  metric,
  methods
)

Arguments

TrainSet

The training set.

resp.var

Indicate the name of the column in the training set that contains the response variable.

trControl

A list of values that define how this function acts. See trainControl and http://topepo.github.io/caret/using-your-own-model-in-train.html. (NOTE: If given, this argument must be named.)

preProcess

A string vector that defines a pre-processing of the predictor data. Current possibilities are "BoxCox", "YeoJohnson", "expoTrans", "center", "scale", "range", "knnImpute", "bagImpute", "medianImpute", "pca", "ica" and "spatialSign". The default is no pre-processing. See preProcess and trainControl on the procedures and how to adjust them. Pre-processing code is only designed to work when x is a simple matrix or data frame.

tuneLength

An integer denoting the amount of granularity in the tuning parameter grid. By default, this argument is the number of levels for each tuning parameters that should be generated by train. If trainControl has the option search = "random", this is the maximum number of tuning parameter combinations that will be generated by the random search. (NOTE: If given, this argument must be named.)

metric

A string that specifies what summary metric will be used to select the optimal model. By default, possible values are "RMSE" and "Rsquared" for regression and "Accuracy" and "Kappa" for classification. If custom performance metrics are used (via the summaryFunction argument in trainControl, the value of metric should match one of the arguments. If it does not, a warning is issued and the first metric given by the summaryFunction is used. (NOTE: If given, this argument must be named.)

methods

Similarly to the method argument in caret's train function, this argument is a list of strings specifying which classification or regression models to use. Possible values are found using names(getModelInfo()). See http://topepo.github.io/caret/train-models-by-tag.html. A list of functions can also be passed for a custom model function. See http://topepo.github.io/caret/using-your-own-model-in-train.html for details.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
ctrl.reg <- trainControl(method = 'cv',               # k-fold cross-validation
number = 5,                  # k = 5
search = 'grid',             # use grid search over paramter space
summaryFunction = defaultSummary,
selectionFunction = 'oneSE', # select optimal tuning parameters by "one standard error" rule
savePredictions = 'final')   # save predicted values of the final model

boston.models <- caretModels(boston.training,    # training set
                             resp.var='cmedv',   # response variable
                             trControl = ctrl.reg,
                             preProcess = c('center', 'scale'),
                             tuneLength = 7,
                             metric = 'RMSE',
                             methods = 'svmRadial')

kforthman/caretStack documentation built on June 21, 2021, 8:38 a.m.