Foundations — Entropy and information gain
This page assumes you have seen nothing. Before you can read a single formula on the parent note, you need a small toolbox: fractions-as-probabilities, what a logarithm is, why base 2, the summation symbol, and averages. We build each one from a picture, in the exact order they stack.
1. A "set" and its labels
Picture a bag of marbles. Some are blue (label "Yes"), some are orange (label "No"). The bag is . We are not doing any maths yet — we are just naming the pile of things we will measure.

Why the topic needs it: entropy is a property of a bag. When the tree splits, it makes smaller bags (bag for value ). Every formula is "measure this bag, then measure the smaller bags".
2. Probability — a fraction that names "how much of the bag"
If the bag has 9 blue and 5 orange out of 14 total:
The little is just an index — a name-tag that walks through the classes one at a time: is blue, is orange. The letter means how many classes there are (here ).
Why the topic needs it: entropy is built entirely out of these . No probabilities, no entropy.
3. The summation symbol — "add up over all the classes"
It is shorthand. Instead of writing we write . With 5 classes it saves a lot of ink.
Why the topic needs it: entropy is a sum over classes. Information gain is a sum over the child bags. If is a blur, every formula is a blur.
4. The logarithm — the "how many doublings?" question
This is the tool the parent uses without ever slowing down. We slow down.
Doubling: . So:
- (start at 1, no doublings needed),
- (one doubling),
- (three doublings, since ).

Why base 2 and not base 10 or ? Because we want to count in yes/no questions. Each yes/no question can split possibilities in half — one bit of information. "How many halvings?" is exactly . That is why the units are called bits.
This is the single reason the entropy formula has a minus sign out front: probabilities are , so their logs are , so makes them back into friendly positive numbers.
5. Surprise — turning "rare" into a number

Check the picture: at the curve sits on the floor (no surprise — you knew it was coming). As shrinks toward the curve rockets up (a one-in-a-million event stuns you). This is the shape the log gives us for free.
Why the topic needs it: entropy is nothing more than the average of this surprise over the bag. Understand and entropy is just "average ".
6. Weighted average — the average that respects size
Plain average of surprises would treat a rare class and a common class equally. That's wrong: a class that fills most of the bag should count more. So we weight each surprise by its own probability :
That is the entropy formula — assembled entirely from the pieces above: probabilities (§2), a sum (§3), a log (§4), and surprise (§5), averaged (§6).
The same weighting logic returns in information gain. There, the "quantity" is each child bag's entropy , and the weight is — the fraction of examples that land in that child.
7. Pure vs. maximally mixed — the two anchor pictures

Everything in between lives on the arch you see in the figure: entropy climbs from (pure), peaks at the balanced middle, and falls back to (pure the other way).
How these foundations feed the topic
Read top to bottom: a labelled bag gives probabilities; probabilities plus base-2 logs give surprise; averaging surprise gives entropy; comparing parent entropy to weighted child entropy gives information gain, which is what Decision Trees use to pick a question.
Where this leads next
- Decision Trees — the machine that repeatedly maximises information gain.
- Gini Impurity — the same "messiness" idea without any logarithm.
- ID3 and C4.5 Algorithms — algorithms built directly on gain and gain ratio.
- Cross-Entropy Loss — the same shape reused in neural nets.
- KL Divergence — surprise generalised to compare two distributions.
- Overfitting and Pruning — what happens when we chase pure leaves too hard.
Equipment checklist
Recall I can state what
and a label are. is a bag of examples; each carries a label (the class we predict). ::: A bag of examples, each tagged with its class.
Recall I can turn counts into
. , always in , and . ::: Divide each class count by the total; fractions sum to 1.
Recall I can read
aloud. Plug in and add all the results. ::: Loop the index over all classes and add.
Recall I know what
asks and why base 2. "How many doublings from 1 to ?" Base 2 because each yes/no question halves possibilities → units are bits. ::: Number of doublings; base 2 gives bits.
Recall I know why the entropy formula has a minus sign.
Probabilities have negative logs; the minus flips them positive. ::: Logs of fractions are negative, so makes surprise positive.
Recall I can define surprise
and its two anchor values. ; (certain, no surprise), bit. ::: ; zero at , one bit at .
Recall I know why we take a weighted average, not a plain one.
Common classes should count more; weight each surprise by its probability (and each child entropy by ). ::: Bigger/likelier pieces should dominate the average.
Recall I know the two entropy extremes.
Pure bag → ; balanced two-class bag → bit (max is in general). ::: 0 when pure, max when evenly mixed.