I searched around CV and the caret documentation but couldn't find an answer to this. I'm using caret in R to tune some random forests for classification trained using ranger. I've made a tuning grid that varies the number of variables sampled, mtry, and the minimum node size, min.node.size in this dataset. I defined the grid as follows:

mtry <- floor(sqrt(ncol(train_x)))

grid_rf <- expand.grid(
  .mtry = c(mtry/4, mtry/2, mtry, mtry*2, mtry*4),
  .splitrule = "gini",
  .min.node.size = c(1, 10, 20)

So this grid should yield 15 models. Next, I set the trainControl function to use out of bag error, trainControl(method = "oob"). There are no repeats, because the method isn't repeated cross-validation. So I would only expect 15 models to be trained and the model with lowest OOB error to be chosen. However, looking at the "Growing trees.. Progress: X%" progress message that ranger prints, I can see that right now it's starting to train the 16th random forest instead of stopping, because it has already hit 100% 15 times and is starting to train a new forest.

Did I misunderstand the trainControl() function? How many models is it supposed to train?

Thanks for reading my post!


1 Answer 1


There's one additional training, the one that produces finalModel, the model trained on "all the training data using the optimal parameter set" (final step in algorithm displayed here). Now with oob scoring, you don't really need to refit because you already were using all the training data, but it appears that caret doesn't make that specialization (I don't see any exceptions for oob scoring around this part of the code, for either train.default or train.recipe).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.