I have data with a few thousand features and I want to do recursive feature selection (RFE) to remove uninformative ones. I do this with caret and RFE. However, I started thinking, if I want to get the best regression fit (random forest, for example), when should I perform parameter tuning (mtry for RF)? That is, as I understand caret trains RF repeatedly on different feature subsets with a fixed mtry. I suppose the optimum mtry should be found after the feature selection is finished, but will the mtry value that caret uses influence the selected subset of features? Using caret with low mtry is much faster, of course.

Hope someone can explain this to me.

  • 3
    $\begingroup$ RF has a robust built-in feature selection - no need to use RFE so one can just tune mtry and be done with it. $\endgroup$
    – Yevgeny
    Sep 5, 2012 at 21:42

2 Answers 2


One thing you might want to look into are regularized random forests, which are specifically designed for feature selection. This paper explains the concept, and how they differ from normal random forests

Feature Selection via Regularized Trees

There's also a CRAN package RRF that's build on the randomForest that will allow you to implement them easily in R. I've had good luck with this methodology myself.

Regarding your initial question, the only advice I can give is that if you have a lot of collinearity then you need to use smaller tree sizes. This allows the algorithm to determine importance with less interference from collinearity effects.


You might be able to use caretFuncs Something like this:

myRFE <- caretFuncs
myRFE$summary <- twoClassSummary  (default is defaultSummary)

rctrl <- rfeControl(method='repeatedcv', repeats=5, number=10,

tctrl <- trainControl(method = "cv",
                      classProbs = TRUE,
                      summaryFunction = twoClassSummary)

rfeObj = rfe(x,y,sizes=seq(1,ncol(x),2),
             # to be passed to train()
             importance=T,  # do not forget this
             metric = "ROC",
             tuneLength = 10,
             # mtry=c(1,3,5,50),
             # specify the exact mtry, or tuneLength
             # can auto truncate the grid to minimal sizes (with or without warning)
             # p <- ncol(x) ... if (mtry < 1 || mtry > p) warning("invalid try: reset to within valid range") try <- max(1, min(p, round(try))) 

Also, one may check valSelRF package. Not sure how it differs from regularized random forest mentioned here.


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.