Visual walkthrough — Entropy and information gain
Step 1 — A bag of marbles: what does "messy" even mean?
WHAT. Picture a cloth bag. Inside are marbles of two colours: some plum (call them "Yes") and some teal (call them "No"). You reach in blind and pull one out. How surprised are you by the colour you get?
WHY. Before we can measure "mess" with a formula, we need to agree on what mess feels like. A decision tree wants tidy bags — bags where you can guess the colour before you even look. The opposite (a bag where you can never guess) is "maximum mess." Everything else is derived from this one feeling.
PICTURE. Three bags, left to right: all-plum (never surprised), lopsided (rarely surprised), half-and-half (a coin flip every time).

Step 2 — Turning "surprise" into a number
WHAT. We invent a function = the surprise of pulling an outcome that had probability . We do NOT guess its formula. Instead we write down two things surprise must obey, and let those choose the formula for us.
WHY. This is the honest way to build a formula: state what you want, then discover what satisfies it — rather than pulling out of a hat.
- : if an event was certain (), seeing it happen tells you nothing new.
- : if two unrelated things happen — a plum marble AND a coin landing heads — their joint probability is the product , but your total surprise should be the two surprises added. Surprise stacks; probability multiplies.
PICTURE. Two dials feeding a totaliser: probabilities enter through a "×" gate, surprises leave through a "+" gate. The device that converts one to the other is the mystery box we solve next.

Step 3 — Only the logarithm turns × into +
WHAT. We look for the one continuous function that turns multiplication of inputs into addition of outputs. That function is the logarithm.
WHY this tool and not another? We need . Ask: which everyday function has that magic property? Not squaring (, that multiplies). Not . The logarithm is defined by exactly this identity: . It is the unique continuous answer, so surprise must be built from a log.
PICTURE. The curve : it explodes toward as (a near-impossible event is enormously surprising) and touches at .

Step 4 — From one outcome's surprise to the whole bag's entropy
WHAT. is the surprise of one particular outcome. Entropy is the surprise you expect on average across every possible outcome, weighted by how often each occurs.
WHY average? A single pull could be a plum or a teal. To rate the bag (not one pull) we ask "how surprised will I be, typically?" — that is the expected value of surprise. You weight each outcome's surprise by its own probability , because likely outcomes happen more often and should count more.
- appears twice: once as the weight (how often), once inside the log (how surprising).
- The sum runs over every class in the bag ( classes total).
PICTURE. A bar chart: each colour's bar height is its surprise , its width is its probability ; entropy is the total shaded area (probability-weighted average height).

Step 5 — The two-colour case: the famous entropy hump
WHAT. With only two colours, and . Plug into the average:
WHY draw the whole curve? Because a tree split slides around, and we want to see which bags are messy. Sweeping from to traces one smooth hump.
PICTURE. The full curve on warm paper: it rises from , peaks at , and falls back to . The three marble bags from Step 1 are marked on it.

Reading the curve at a glance:
- Left foot : all teal, no surprise, .
- Peak : perfect coin flip, maximum surprise, bit.
- Right foot : all plum, no surprise, .
Step 6 — The edge case: what is ?
WHAT. At the formula has a term . But , and "" looks undefined. We must decide what it means here.
WHY it matters. A pure node (all one colour) has some class with . If this term blew up, entropy of a pure node would be undefined — nonsense, since a pure bag is the least messy thing possible. We need the limit, not the naive plug-in.
The resolution. As , the weight shrinks to zero faster than grows. Their product is squeezed to :
PICTURE. Zoom near : the tiny sliver of area (width , height ) collapses to nothing as — the curve lands smoothly on the axis, no spike.

So a pure node genuinely has . Both feet of the hump are honest zeros.
Step 7 — The other edge: more colours push the ceiling up
WHAT. With two colours, the most mess is bit. What if the bag has equally likely colours? Set every :
- bit (matches the hump's peak).
- bits.
- bits.
WHY care? Entropy of bit is the max only for two classes. Comparing entropies across problems with different numbers of classes needs this ceiling. And uniform () is always the messiest arrangement — no colour to bet on.
PICTURE. Bars for each at uniform mix, with the maximum entropy rising in staircase steps.

Step 8 — Why information gain can never be negative (the concavity picture)
WHAT. Splitting bag on a question produces child bags . Information gain is We claim the subtracted term (the weighted child mess) never exceeds the parent mess , so .
WHY it's true — geometrically. The entropy curve is concave (it bulges upward like a dome). For any dome-shaped curve, the height above a mixture point is at least the weighted average of the heights above the parts — this is Jensen's inequality. The parent is the weighted average of the children's ; the parent sits on the curve above the straight line joining the children.
PICTURE. Two children marked on the entropy hump, the straight chord joining them, and the parent point sitting on the curve above the chord. The vertical gap is the information gain.

Worst case: children have the same as the parent (the chord touches the curve) → gap → useless split, . A split can never raise uncertainty.
The one-picture summary
Everything above, compressed: surprise curve → averaged into the entropy hump → a split's gain is the concavity gap.

Recall Feynman retelling — say it back in plain words
We started with a bag of coloured marbles and asked "how surprised am I by a pull?" We demanded two obvious rules — certainty is boring (), and unrelated surprises add while their chances multiply. The only function that turns multiply into add is the logarithm, so surprise had to be ; the minus makes it positive, base 2 gives bits. Entropy is just the average surprise over the whole bag: . For two colours it's a smooth hump — zero at the pure ends, a full bit at the 50/50 peak. At the pure end the scary-looking is really (the weight shrinks faster than the log grows), so pure bags are honestly zero mess. With colours the ceiling climbs to . Finally, because the hump bulges upward (concave), a parent always sits above the line joining its children — that vertical gap is the information gain, which is why gain can never be negative and why the tree greedily grabs the biggest gap.
Connections
- Parent topic — Entropy & Information Gain
- Decision Trees — the hump-gap is computed at every candidate split.
- Gini Impurity — same concave-dome argument, no logarithm.
- ID3 and C4.5 Algorithms — turn these gaps into a tree.
- Cross-Entropy Loss — the same surprise-average in neural nets.
- KL Divergence — measures the extra surprise from using the wrong distribution.
- Overfitting and Pruning — chasing to pure leaves can memorise noise.