Random Forest – Using Variable Importance for Feature Selection in Random Forest Models

bootstrapdata-leakagefeature selectionrandom forest

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?

Best Answer

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.