# Almost reverse feature importances by Extratrees vs RandomForest

I am using scikit-learn to find feature importances using ExtraTreesClassifier and RandomForestClassifier, both of which have feature_importances_ attribute.

The data has 4 numeric predictors, 2 binary predictors and 2 multiclass (3 each) predictors which are converted to 6 dummy variables. There are about 12000 rows in dataset. The outcome variable is binary.

Following are the plots of features importances by 2 classifiers:

As can be seen by above figures, the importances are almost reverse of each other. SM,SL,SB and LM are most important by ET and almost least important by RF. Inverse is true for HT,WST,WT and A.

What could be the reason for such discrepancy? What does it tell about the data and the outcome variable? What is the best way to get feature importances reliably? Thanks for your insight.

Edit: I kept n_estimators=250. Results are similar with n_estimators=100

• How many trees did you use? – Sycorax Dec 8 '18 at 1:49
• I kept n_estimators=250. Results are similar with n_estimators=100. – rnso Dec 8 '18 at 1:50
• How is feature importance measured in the case of ET? There are different ways to measure feature importance in an RF generally, are RF and ET using the same methodology? (+1 fun question) – usεr11852 Dec 16 '18 at 23:48
• As I mentioned in question above, I used feature_importance_ attribute: scikit-learn.org/stable/modules/generated/… I am not sure how that is calculated. – rnso Dec 17 '18 at 2:07
• Are you sure that your model is not overfitting? – jonnor Jan 9 at 0:28

## 3 Answers

RandomForest and ExtraTrees will tend to supress redundant features. If a feature A is used already, and feature B does not add any new information over A it won't get used. And it will thus not contribute to feature importances, even though it is in general a highly predictive variable.

Which features gets picked as important among redundant features is random, and even the same model type is likely to give different feature importances in these cases each time it is trained. You can test this by passing different random_state variables.

Redundant features should have high mutual information. And they might be linearly correlated.

• Which features here are likely to be linearly correlated? Are you suggesting I should check that and use only 1 amongst linearly correlated variables? – rnso Dec 17 '18 at 2:11
• "If a feature A is used already, and feature B does not add any new information over A it won't get used." This isn't true. Consider the case where A and B are identical copies. Random forests choose the variable to split from a random subset. A and B have equal probability of appearing in this subset, so sometimes A will be selected first, and sometimes B. The trees are fit independently. So, A and B would be expected to occur with equal frequency across trees in the forest, on average. Of course, there will be variability due to randomness from bagging and random feature selection. – user20160 Dec 17 '18 at 2:58

Difference would be there since these two algorithms work in a different way.
ExtraTreeClassifier: fits a number of randomized decision trees (a.k.a. extra-trees) on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting.
whereas,
RandomForest: fits a number of decision tree classifiers on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting. The sub-sample size is always the same as the original input sample size but the samples are drawn with replacement if bootstrap=True so please check if you put bootstrap=True or False.

Now the question is how can you decide what is the correct feature importance order, use three or four algorithms to find feature importance and let the majority wins! (almost every classification algorithm in scikit-learn offers feature importance)

Thanks!

1. We could take the model that has better accuracy on test set and consider its feature importance as better
2. Compute feature importance from xgboost and compare the results
3. Assuming that features SM/SL/SB and LM/LH/LG represent the 2 multi-classes, it looks like ET has grouped those variables together unlike RF
• Point 1 seems valid but is there any reference saying that better prediction is related to better feature importances, though this seems likely. Point 2: why only xgboost, why not many others also? Point 3 is just an observation. Points 2 and 3 are not really any answers. – rnso Dec 18 '18 at 12:04