Why Feature Importance Misleads
Understanding how Gini Impurity feature importance in tree models misleads developers on correlated and high cardinality features.
The Illusion of Default Feature Importance
In Python libraries like Scikit-Learn or XGBoost, developers frequently call model.feature_importances_ to explain their models.
Relying blindly on default feature importance output leads to dangerous misinterpretations.
Default tree feature importance (MDI / Gini Importance) calculates how much each feature split reduces impurity. This calculation suffers from Two Severe Flaws:
FLAW 1: Cardinality Bias ──► High cardinality features (IDs, Zip Codes) get artificially inflated scores!
FLAW 2: Correlation Split ──► Strongly correlated features split importance scores, making both look weak!
Flaw 1: Cardinality Bias (High Cardinality Inflation)
Features with many unique values (like User_ID, Random_Noise_Float, ZIP_Code) offer thousands of candidate split thresholds.
Tree algorithms split on these high cardinality features repeatedly by chance, artificially inflating their Gini importance scores even if the column is pure random noise!
Feature Experiment:
- Feature 1: True Binary Signal (0 or 1) ──► Gini Importance = 0.15 (Looks Low!)
- Feature 2: Pure Random Float (High Card) ──► Gini Importance = 0.85 (Looks High!)
Default Gini importance ranks pure random noise as the most important feature!
Flaw 2: Correlation Masking
When two features $X_1$ and $X_2$ are strongly correlated (for example House_Square_Feet and Room_Count):
- The tree algorithm arbitrarily splits on $X_1$ at one node, and $X_2$ at another.
- Both features split the total importance score between them ($50%$ each).
- Individually, both features appear half as important as an uncorrelated standalone feature of equal predictive power!
Unbiased Alternatives
┌──────────────────────────┬──────────────────────────┐
│ PERMUTATION IMPORTANCE │ SHAP VALUES │
├──────────────────────────┼──────────────────────────┤
│ Shuffles a single feature│ Computes game theoretic │
│ column on test data and │ marginal contributions │
│ measures performance drop| across all feature │
│ score. Model agnostic! │ combinations. Gold std! │
└──────────────────────────┴──────────────────────────┘
Permutation Feature Importance
- Compute baseline validation score $S_{\text{base}}$ on clean test set.
- Randomly shuffle the values of feature column $j$ in the test set, breaking its relationship with target $y$.
- Compute new validation score $S_{\text{shuffled}}$.
- Importance $= S_{\text{base}} - S_{\text{shuffled}}$.
If shuffling feature $j$ causes validation performance to collapse, feature $j$ is genuinely important!
Say this out loud
Default Gini feature importance in tree models misleads developers by inflating high cardinality features and splitting scores across correlated variables. Permutation feature importance and SHAP values provide unbiased alternatives. Permutation importance shuffles individual test features to measure true validation performance drops.
Followups to expect
- Why does Permutation Importance struggle with correlated features? Shuffling one correlated feature creates unrealistic out-of-distribution sample combinations (for example 5,000 square foot house with 1 room), overestimating performance drops.
- What is Drop Column Importance? Retraining a model from scratch after dropping a feature column entirely, measuring true baseline performance drops at the cost of high compute time.
Check yourself
Why does default Gini Impurity Feature Importance in Random Forests heavily bias toward high cardinality features like User ID or ZIP code?