Feature importance from trees
WHAT are we computing?
The three ingredients:
- Impurity : how mixed a node is (Gini or entropy for classification, variance/MSE for regression).
- Impurity decrease : how much the split cleans up the node.
- Weighting : a split high in the tree affects many samples → counts more.
HOW: derive from first principles
WHY do we weight children? A parent node with samples splits into a left child () and right child (). We compare the parent's impurity to the average impurity of the children — but a child holding more samples should count more. So we weight children by their sample fractions:
Why this is always : greedy tree algorithms choose the split that maximizes this drop, and impurity is a concave function, so splitting can never increase (weighted) impurity. That's why importances are non-negative.
Now multiply by the arrival weight (fraction of all data that reaches node ) and sum over every node splitting on → gives above.
Forests: average over trees
For a Random Forest / GBM with trees, importance is the mean over trees, usually normalized to sum to 1:

Worked Example 1 — one split, Gini
Root has 10 samples: 5 positive, 5 negative. A split on feature gives:
- Left: 4 samples (4 pos, 0 neg)
- Right: 6 samples (1 pos, 5 neg)
Step 1 — parent impurity. Why? Baseline mixed-ness.
Step 2 — child impurities. Why? Measure how clean each side got.
Step 3 — weighted child impurity. Why? Big child counts more.
Step 4 — impurity decrease. Why? Cleanup achieved.
Step 5 — arrival weight. Root sees all data, .
Worked Example 2 — deeper node weighting
Suppose splits at a node reached by only 3 of 10 samples, with .
Step — apply arrival weight. Why? A split affecting few samples shouldn't dominate.
Even with a bigger local (0.4 > 0.3333), (0.12) ranks below (0.3333) because 's split touched everyone. This is the whole reason for .
Normalized: , .
Worked Example 3 — regression (variance drop)
Node with , . Split into and .
Step 1 — parent variance. Step 2 — child variances. Each child: or , var . Step 3 — weighted. Step 4 — decrease. . Big drop → this feature separates well.
Recall Feynman: explain to a 12-year-old
Imagine sorting a messy box of red and blue marbles into cleaner piles. Each "question" you ask (like is it bigger than a coin?) that makes the piles neater earns points. A question that splits ALL the marbles into perfect red-only and blue-only piles earns lots of points; a question that only helps 3 marbles earns few. Add up each question-type's points across the whole game — the questions with the most points are the most important features. But careful: a question with tons of possible answers (like exact weight in grams) can "cheat" and look important even when it's just memorizing.
Flashcards
What does MDI (Mean Decrease in Impurity) measure?
Write the weighted impurity decrease at a node.
Why multiply each node's by ?
Give the Gini impurity formula and why it works.
Why is impurity decrease always non-negative?
What impurity is used in regression trees?
Main bias of MDI feature importance?
Fix for MDI's biases?
What happens to importance among two correlated features?
How is forest importance obtained from tree importances?
Connections
- Decision Trees — MDI is a byproduct of the same impurity used to grow the tree.
- Gini vs Entropy — choice of changes importance values.
- Random Forests — importance averaged over many trees for stability.
- Gradient Boosting — also exposes split-based importances (gain/cover/frequency).
- Permutation Importance — unbiased, model-agnostic alternative.
- SHAP Values — game-theoretic attribution fixing MDI biases.
- Bias-Variance Tradeoff — training MDI overestimates due to overfitting.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Feature importance ka core idea simple hai: decision tree har split pe impurity (matlab node kitna "mixed" hai) ko kam karta hai. Jo feature jitni zyada impurity kam karta hai across saare splits, wo utna hi important maana jaata hai. Isko MDI ya Gini importance kehte hain. Formula bas ek weighted sum hai: har node pe impurity drop nikaalo, usko (kitne samples us node tak pahunche) se multiply karo, aur us feature ke saare nodes ka total le lo.
Weighting kyun? Socho ek split root pe hai jo saare 10 samples ko affect karta hai, aur doosra split neeche sirf 3 samples ko. Root wala split zyada matter karega, isiliye multiply karte hain. Classification mein impurity Gini hoti hai (do random draws alag class ke aane ki probability), aur regression mein variance/MSE hoti hai.
Ek badi warning: MDI biased hota hai. High-cardinality ya continuous features (jinke bahut saare split points hote hain) noise fit karke bhi important dikhne lagte hain. Aur agar do features correlated hain, to ek use hote hi doosra redundant ho jaata hai aur uski importance almost zero ho jaati hai — jabki wo actually predictive tha. Isliye serious kaam mein permutation importance ya SHAP use karo, jo held-out data pe honestly measure karte hain. MDI quick intuition ke liye best hai, final decision ke liye cross-check zaroori.