I have read quite a number of posts on the caret package and I am specifically interested in the train function. However, I am not completely sure if I have understood correctly how the train function works.
To illustrate my current thoughts I have composed a quick example.
First, one specifies a parameter grid. Let's say I use use the method gbm, accordingly the parameter grid for my model could look like:
grid <- expand.grid( .n.trees=seq(10,50,10), .interaction.depth=seq(1,4,1), .shrinkage=c(0.01,0.001), .n.minobsinnode=seq(5,20,5))
Subsequently, the control parameters for train (trainControl) are defined. I would like to know if my thoughts on cross-validation using train are correct, and hence, in this example I use the following:
train_control <- trainControl('cv',10)
At last, the train function is executed. For example:
fit <- train(x,y,method="gbm",metric="Kappa",trControl=train_control,tuneGrid=grid)
Now the way I presume that train works is the following:
- In the above example there are 160 (5*4*2*4) possible parameter combinations
- For each parameter combination train performs a 10-fold cross validation
- For each parameter combination and for each fold (of the 10 folds) the performance metric (Kappa in my example) is computed (in my example this implies that 1600 Kappa's are computed)
- For each parameter combination the mean of the performance metric is computed over the 10 folds
- The parameter combination that has the best mean performance metric are considered the best parameters for the model
My question is simple, are my current thoughts correct?