Feature importance from trees
2.3.8· AI-ML › Tree-Based & Instance Methods
KYA compute kar rahe hain hum?
Teen ingredients:
- Impurity : ek node kitna mixed hai (classification ke liye Gini ya entropy, regression ke liye variance/MSE).
- Impurity decrease : split ne node ko kitna saaf kiya.
- Weighting : tree mein upar ka split zyada samples affect karta hai → zyada count hota hai.
KAISE: first principles se derive karo
WHY children ko weight karte hain? Ek parent node jisme samples hain woh ek left child () aur right child () mein split hota hai. Hum parent ki impurity ko children ki average impurity se compare karte hain — lekin jis child mein zyada samples hain woh zyada count karna chahiye. Isliye hum children ko unke sample fractions se weight karte hain:
Yeh hamesha kyun hai: Greedy tree algorithms woh split choose karte hain jo is drop ko maximize kare, aur impurity ek concave function hai, isliye splitting kabhi (weighted) impurity badha nahi sakti. Isliye importances non-negative hoti hain.
Ab arrival weight se multiply karo (fraction of all data jo node tak pahunchta hai) aur par split karne wale har node pe sum karo → is se upar wala milta hai.
Forests: trees par average karo
Ek Random Forest / GBM jisme trees hain, importance trees ka mean hoti hai, usually 1 sum karne ke liye normalize ki gayi:

Worked Example 1 — ek split, Gini
Root mein 10 samples hain: 5 positive, 5 negative. Feature par split se milta hai:
- Left: 4 samples (4 pos, 0 neg)
- Right: 6 samples (1 pos, 5 neg)
Step 1 — parent impurity. Kyun? Baseline mixed-ness.
Step 2 — child impurities. Kyun? Measure karo ki har side kitni clean hui.
Step 3 — weighted child impurity. Kyun? Bada child zyada count karta hai.
Step 4 — impurity decrease. Kyun? Jo cleanup achieve hua.
Step 5 — arrival weight. Root sabhi data dekhta hai, .
Worked Example 2 — deeper node weighting
Maan lo ek aisi node par split karta hai jo sirf 10 mein se 3 samples tak pahunchi hai, aur hai.
Step — arrival weight lagao. Kyun? Jo split thode samples affect kare woh dominate nahi karni chahiye.
Zyada local hone ke bawajood (0.4 > 0.3333), (0.12) ka rank (0.3333) se neeche hai kyunki ki split ne sabko touch kiya. Yahi reason hai ka.
Normalized: , .
Worked Example 3 — regression (variance drop)
Node jisme , hai. Split into aur .
Step 1 — parent variance. Step 2 — child variances. Har child: ya , var . Step 3 — weighted. Step 4 — decrease. . Bada drop → yeh feature ko achhi tarah separate karta hai.
Recall Feynman: 12-saal ke bachche ko samjhao
Socho tum ek messy box mein red aur blue marbles ko saaf piles mein sort kar rahe ho. Har "sawaal" jo tum poochho (jaise kya yeh ek coin se bada hai?) jo piles ko neater banaye, woh points earn karta hai. Ek sawaal jo SAARE marbles ko perfect red-only aur blue-only piles mein split kare woh bahut points earn karta hai; ek sawaal jo sirf 3 marbles ki help kare woh kam points paata hai. Puri game mein har sawaal-type ke points add karo — sabse zyada points wale sawaal most important features hain. Lekin savdhan raho: ek sawaal jiske bahut saare possible answers hain (jaise grams mein exact weight) "cheat" kar sakta hai aur important lag sakta hai jab woh sirf memorize kar raha ho.
Flashcards
MDI (Mean Decrease in Impurity) kya measure karta hai?
Node par weighted impurity decrease likhो.
Har node ke ko se multiply kyun karte hain?
Gini impurity formula do aur kyun kaam karta hai.
Impurity decrease hamesha non-negative kyun hoti hai?
Regression trees mein kaun si impurity use hoti hai?
MDI feature importance ka main bias kya hai?
MDI ke biases ka fix kya hai?
Do correlated features ki importance mein kya hota hai?
Trees ki importances se forest importance kaise milti hai?
Connections
- Decision Trees — MDI usi impurity ka byproduct hai jo tree grow karne mein use hoti hai.
- Gini vs Entropy — ka choice importance values badalta hai.
- Random Forests — stability ke liye bahut saare trees par importance average ki jaati hai.
- Gradient Boosting — split-based importances bhi expose karta hai (gain/cover/frequency).
- Permutation Importance — unbiased, model-agnostic alternative.
- SHAP Values — MDI biases fix karne wala game-theoretic attribution.
- Bias-Variance Tradeoff — training MDI overfitting ki wajah se overestimate karta hai.