15
$\begingroup$

CARET will automatically use a pre-specified tuning grid to build various models before selecting a final model, and then training the final model on the full training data. I can supply my own tuning grid with only one combination of parameters. However even in this case, CARET "selects" the best model among the tuning parameters (even though there is only one in this case), and then fits the final model to all the training data. This is an extra step I'd like to avoid.

How do I simply skip the model search step across variations in the tuning grid and force CARET to build on all the training data (other than calling the underlying model library directly)?

$\endgroup$
  • 1
    $\begingroup$ The question is rather unclear, which probably explains why you've received replies answering different questions, namely 1) How do I tell caret to skip model validation AND tuning? and 2) How do I turn off only model tuning? $\endgroup$ – Johan Larsson Mar 14 '16 at 10:18
17
$\begingroup$

You can specify method="none" in trainControl. For example:

train(Species ~ ., data=iris, method="rf", tuneGrid=data.frame(mtry=3),
  trControl=trainControl(method="none"))

I'm not sure when this was implemented.

$\endgroup$
9
$\begingroup$

The best way would be to explicitly supply the tuneGrid dataframe. For instance, random forest has only one tuning parameter, 'mtry', which controls the number of features selected for each tree.

To set mtry at a specific value, you might choose the randomForest default (?randomForest) do this:

model <- train(x = X, y = Y, method = 'rf', tuneGrid = data.frame(.mtry = M))

where M is the one value of the tuning parameter you wish to use.

for multiple tuning parameters do this:

tuneGrid = data.frame(.par1 = P1, .par2 = P2, .par3 = P3)
$\endgroup$
  • $\begingroup$ Welcome to our site, Brent! Thanks for following up with this old question. $\endgroup$ – whuber Jul 12 '12 at 12:36
  • 4
    $\begingroup$ The suggestion below method="none" is the better solution. $\endgroup$ – topepo May 8 '14 at 12:51
1
$\begingroup$

I don't think it is possible (at least it was not possible as of a few versions ago). One can reduce the performance impact by setting up just a single resampling partition in training data (but caret would still train a model twice)

This sounds like a useful feature to have so I would ping the author of the package.

$\endgroup$
  • $\begingroup$ Sorry this answer is obsolete now $\endgroup$ – smci Jul 16 '15 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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