The preferred method in R to train known ML models is to use the caret
package and its generic train
method. My question is what's the relationship between the tuneGrid
and trControl
parameters? as they are undoubtedly related and I can't figure out their relationship by reading the documentation ... for example:
library(caret)
# train and choose best model using cross validation
df <- ... # contains input data
control <- trainControl(method = "cv", number = 10, p = .9, allowParallel = TRUE)
fit <- train(y ~ ., method = "knn",
data = df,
tuneGrid = data.frame(k = seq(9, 71, 2)),
trControl = control)
If I run the code above what's happening? how do the 10 CV folds each containing 90% of the data as per the trainControl
definition are combined with the 32 levels of k
?
More concretely:
- I have 32 levels for the parameter
k
. - I also have 10 CV folds.
Is the k-nearest neighbors model trained 32*10 times? or otherwise?