Entropy and information gain
2.3.2· AI-ML › Tree-Based & Instance Methods
HUM KYA MEASURE KAR RAHE HAIN?
YE EXACT FORMULA KYUN? Hum ek aisa number chahte hain jo:
- ho jab hum certain hon (ek class ki ho),
- bada ho jab hum maximally confused hon,
- independent information ke liye additive ho.
Ye teeno requirements milke ek shape ko force karti hain. Chaliye isse derive karte hain.
ENTROPY KO SCRATCH SE KAISE DERIVE KAREIN
Hum do properties demand karte hain:
- Certainty mein koi info nahi: .
- Independent events add hote hain: agar do independent cheezein probs aur se hoti hain, to joint prob hogi, aur total surprise add honi chahiye: .
Sirf ek hi continuous function hai jo multiplication ko addition mein convert karta hai — logarithm: Minus sign ise positive banata hai (kyunki ). Base chunne se bits milte hain.
Entropy sirf distribution par average surprise hai:

Information Gain
WEIGHTS KYUN? Splitting ke baad, ek random example child mein probability se land karta hai. Expected leftover entropy, child entropies ka weighted average hai. Gain = parent entropy − expected child entropy. Ye kabhi negative nahi ho sakta (splitting uncertainty badha nahi sakti, ki concavity ki wajah se).
Worked Example 1 — ek single split
Dataset: 14 examples, 9 "Yes", 5 "No". Attribute Wind ∈ {Weak, Strong}.
- Weak (8 examples): 6 Yes, 2 No
- Strong (6 examples): 3 Yes, 3 No
Step 1 — parent entropy. Ye step kyun? Humein question se pehle ka "mess" ek baseline ki tarah chahiye.
Step 2 — child entropies. Kyun? Strong 50/50 mess hai → maximal 1 bit; Weak Yes ki taraf jhukta hai → kam messy.
Step 3 — weighted child entropy. Weight kyun? Bade children average outcome par zyada matter karte hain.
Step 4 — gain. Itna chhota kyun? Wind ne cheezein barely saaf ki — shayad best split nahi hai ye.
Worked Example 2 — ek perfect split
3 Yes, 3 No. Attribute split karta hai: {3 Yes} aur {3 No} mein.
- bit (perfect 50/50).
- Har child pure hai → .
- Weighted child entropy .
- bit.
Maximal kyun? Ek question ne saari uncertainty remove kar di — dream split.
Forecast-then-Verify
Common Mistakes (Steel-manned)
Gini — fast cousin (YE KYUN EXIST KARTA HAI)
Active Recall
Recall Entropy logarithm kyun use karta hai?
Kyunki hum chahte hain independent information add ho: . Sirf hi independent probabilities ke multiplication ko sum mein convert karta hai. Base 2 ⇒ bits.
Recall Kya information gain negative ho sakta hai?
Nahi. concave hai, isliye child entropies ka weighted average kabhi parent se zyada nahi hota. Worst case IG (ek useless split).
Recall Kaunsi value binary entropy maximize karti hai aur wo kya hai?
, jo bit deta hai.
Recall 12 saal ke bachche ko explain karo
Socho ek bag mein laal aur neele marbles hain. Agar sab laal hain, to ek nikaalte waqt kabhi surprise nahi hoga — ye hai zero mess (entropy 0). Agar aadhe-aadhe hain, to har baar nikalna ek coin flip hai — maximum mess (1 bit). Ek accha "question" bag ko aisa split karta hai ki har chhota bag mostly ek color ka ho. Information gain ye hai ki poochh ke kitna messiness remove hua. Tree pehle wahi question poochna rakhta hai jo sabse zyada mess remove karta hai.
Mnemonic
Flashcards
Decision tree node mein entropy kya measure karta hai?
Entropy formula likho.
Entropy mein logarithm kyun?
p=0.5 par binary entropy?
Information gain formula?
Child entropies ko se weight kyun karte hain?
Kya information gain negative ho sakta hai?
Information gain mein kaunsa bias hai aur iska fix kya hai?
Gini impurity formula?
SplitInfo formula?
Connections
- Decision Trees — entropy/IG node splitting drive karte hain.
- Gini Impurity — alternative impurity measure (CART).
- ID3 and C4.5 Algorithms — IG aur Gain Ratio use karte hain.
- Cross-Entropy Loss — neural nets mein same shape.
- KL Divergence — entropy generalized to compare distributions.
- Overfitting and Pruning — IG se pure leaves overfit kar sakti hain.