How are feature_importances in RandomForestClassifier determined?
random-forestfeature-importancescikit-learndecision-treemachine-learning
Abstraction: Scikit-learn random forest feature importance via weighted impurity reduction
Key points:
- Feature importance is the sum of weighted impurity decreases at all nodes where a feature is used as a split:
n_samples impurity - n_left impurity_left - n_right * impurity_right - Accumulated importances are divided by root node's
weighted_n_node_samples, then optionally normalized to sum to 1.0 - Implemented in Cython (
compute_feature_importances) iterating over all tree nodes - Verified manually on iris dataset: computed values match
clf.feature_importances_(petal width=0.923, petal length=0.064) - All classes assumed to have equal weight (weight=1); be careful about weighted cases
Connections: Scikit Learn · Random Forest · Feature Importance · Decision Trees