I'm currently trying to convince my colleague that his method of doing feature selection is causing data leakage and I need help doing so.

The method they are using is as follows: They first run a random forest on all variables and get the feature importance measure; MeanDecreaseAccuracy. They then remove all variables that score low on this measure and re-run the forest and report the out of bag error rate as the error for the model.

They argue that since the MeanDecreaseAccuracy measure is calculated using the bootstrap and out of bag records that there is no data leakage. I am trying to convince them that since the variable importance measure uses ALL data (in bag records to build the trees and out of bag records to obtain the decrease in accuracy) there is data leakage if they use this measure to do feature selection in this manner.

My solution for them was that they cannot use the out of bag error measure if they want to do feature selection, they will have to set up a proper cross validation split and perform the feature selection on the training sets only.

Am I incorrect here? Can anyone think of a convincing argument (example or paper) that I can show my colleague?

  • $\begingroup$ you might like to read up on boruta $\endgroup$
    – Sycorax
    Commented Apr 16, 2019 at 14:56
  • $\begingroup$ Yes I am familiar with boruta, but this isn't about the merits of boruta vs. traditional random forest importance, rather the correct implication of feature selection. From what I understand of boruta it would have the same issues if applied in the manner I describe above. $\endgroup$
    – astel
    Commented Apr 16, 2019 at 17:49
  • $\begingroup$ sure, they're a way to misuse any tool. but I've found it helpful to "yes-but" the bad ideas that other people have instead of saying "no", as in "Yes, we can use random forest to do feature selection. Here's a good way that we can do that..." $\endgroup$
    – Sycorax
    Commented Apr 16, 2019 at 17:51

1 Answer 1


You are entirely correct!

A couple of months ago I was in the exact same position when justifying a different feature selection approach in front of my supervisors. I will cite the sentence I used in my thesis, although it has not been published yet.

Since the ordering of the variables depends on all samples, the selection step is performed using information of all samples and thus, the OOB error of the subsequent model no longer has the properties of an independent test set as it is not independent from the previous selection step.

- Marc H.

For references, see section 4.1 of 'A new variable selection approach using Random Forests' by Hapfelmeier and Ulm or 'Application of Breiman’s Random Forest to Modeling Structure-Activity Relationships of Pharmaceutical Molecules ' by Svetnik et al., who address this issue in context of forward-/backward feature selection.


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.