2.3.2 · D3Tree-Based & Instance Methods

Worked examples — Entropy and information gain

3,578 words16 min readBack to topic

Everything below uses only these two formulas, restated so you never scroll up — and every symbol is defined in plain words first.


The scenario matrix

Every entropy/IG problem you will ever meet is one of these case classes. The grid below is a true matrix: rows = how pure the node is, columns = single node vs a split vs a trap. Every filled cell names the example that covers it.

purity ↓ \ situation → Single node (just ) A split (compute ) Special / edge case
Pure () Ex 1 (C1) Ex 9 limit (C9)
Balanced () Ex 2 (C2) Ex 5 perfect split (C5)
Skewed binary Ex 3 (C3) Ex 8 word problem (C8)
Multi-class () Ex 4 (C4) Ex 10 compare features (C10)
Any purity, bad split Ex 6 useless split (C6) Ex 7 ID trap + SplitInfo=0 (C7)

So the ten case classes map onto this grid: C1–C4 are single-node entropy of increasing complexity; C5–C6 are the two extremes of a split (all mess removed / none removed); C7 is the trap plus its degenerate denominator; C8 translates words; C9 probes the limit; C10 is the exam-style feature race. We now walk every cell.

Figure — Entropy and information gain
Figure s01 — binary entropy curve. Alt text: a smooth lavender arch of against ; it touches zero at and (both marked "pure, " in mint) and peaks at a coral dot bit. Its three landmarks: zero at both pure ends, a peak of 1 bit at 50/50, and a concave (upward-bulging) shape — that concavity is why gain can never be negative. Keep this picture in mind for every example below.


Ex 1 — Pure node (C1)


Ex 2 — Balanced binary, the maximum (C2)


Ex 3 — Skewed binary with ugly logs (C3)


Ex 4 — Multi-class: the ceiling isn't 1 (C4)

Figure — Entropy and information gain
Figure s02 — the entropy ceiling grows as . Alt text: butter-yellow bars, one per class-count from 2 to 10, each labelled with its height ; the bars climb from at to about at . The slow climb is why comparing raw entropies across different class-counts is unfair.


Ex 5 — Perfect split, gain equals parent (C5)

Figure — Entropy and information gain
Figure s03 — a perfect split empties the uncertainty bar. Alt text: a tall coral parent bar labelled "parent " splits (lavender arrow "split removes ALL mess") into two flat mint bars labelled "child "; the whole bar of uncertainty disappears.


Ex 6 — Useless split, gain exactly zero (C6)


Ex 7 — High-cardinality trap + Gain Ratio (C7)


Ex 8 — Word problem (C8)


Ex 9 — Limiting behaviour as (C9)


Ex 10 — Exam twist: pick the winning feature (C10)

Figure — Entropy and information gain
Figure s04 — Outlook vs Wind information gain. Alt text: two bars, a short lavender "Wind" bar labelled bits beside a tall mint "Outlook" bar labelled bits; Outlook towers over Wind, so the decision is visual once you plot it.


Recall

Recall Why can gain never be negative (seen across Ex 5–6)?

Entropy is concave, so the weighted average of child entropies never exceeds the parent's. Worst case the children mirror the parent (Ex 6) → .

Recall Ex 4 catch: is "max entropy = 1" always true?

No — that's binary only. For equal classes, ( for 3 classes).

Recall Ex 7 catch: why did raw IG lie?

It rewards shattering data into singletons. Dividing by SplitInfo (Gain Ratio) cancels the fake reward, exposing the ID-column trap.

Recall What if SplitInfo = 0 in Gain Ratio?

Only single-valued attributes hit that; they split nothing, so both and SplitInfo are and the attribute is simply excluded — the zero denominator never selects a split.


Connections