Although the obvious answer to my question is yes, since
caret is a professional, well-known tool, I tend to be skeptical when using implemented functionality from other packages.
caret provides function
train which gives you the ability to tune your model by providing a searching grid of the parameters. An additional argument of
train is the preprocessing method. Let's say I want to train an SVM with a radial kernel and have my data scaled. A way to achieve this is with the following code:
library(caret) fitControl <- trainControl(method = "repeatedcv", number = 10, repeats = 10) model<- train(Class ~ ., data = train_xy, method = "svmRadial", preProc = c('center', 'scale'), tuneLength = 8, trControl = fitControl)
My question is: when applying center and scale preprocessing on the data, does
caret calculate mean and standard deviation based only on the training set (9 folds) and then apply it on the tuning fold? Or does it preprocess the data before assigning examples to training and tuning sets? In my opinion this is data snooping and should be avoided even during model tuning, despite the fact that the accuracy of this step doesn't account for out-of-sample model accuracy.
Sorry, that was a long post for a yes/no answer.