Part V — Non-Linear Models, Trees, Ensembles & Kernel Methods · Chapter 1

Decision trees & information gain

Hook

Given ten points of two classes scattered along a line, where's the one cut that tells you the most?

Intuition
Split at 3.0 — information gain = 0.171 bits

Drag the dashed line left and right. Some spots leave both sides a genuine mix of orange and grey — barely worth the split. Somewhere in the middle, one side becomes almost entirely one class. That's the split that actually teaches you something.

Formalize

A decision tree is greedy: at every node, it tries every possible threshold and keeps whichever one removes the most uncertainty. That removed uncertainty is information gain — the entropy chapter's own formula, applied to a parent and its two children:

IG=H(parent)(nLnH(left)+nRnH(right))\text{IG} = H(\text{parent}) - \left(\frac{n_L}{n}H(\text{left}) + \frac{n_R}{n}H(\text{right})\right)
  • IG — the information gain: how much uncertainty a split removes.
  • H(parent)H(\text{parent}) — the entropy of the node before splitting.
  • H(left)H(\text{left}), H(right)H(\text{right}) — the entropy of each child node after splitting.
  • nLn_L, nRn_R — the number of points that land in the left and right child.
  • nn — the total number of points at the parent node.
  1. The second term is the children's weighted entropy

    It's the entropy of each child node, weighted by how many points landed on that side — so a child with more points counts for more of the average.

  2. A good split lowers that weighted average a lot

    A split is good exactly when the children's weighted average entropy is much lower than the parent's entropy you started with.

Play
H(left, n=2) = 0.000, H(right, n=8) = 1.000
Parent H = 0.971, weighted child H = 0.800, gain = 0.171 bits

Now watch both sides' entropy directly instead of just the final gain. Push the split to an edge and one side goes empty (entropy 0, nothing left to weigh) while the other still holds the full mess. The best split isn't the one that empties a side fastest — it's the one that minimizes the weighted average.

Worked example

This dataset is 6 of one class, 4 of the other.

  1. Compute the parent's entropy
    (0.6log20.6+0.4log20.4)0.971 bits-(0.6\log_2 0.6 + 0.4\log_2 0.4) \approx 0.971 \text{ bits}
  2. Split at 5.5 and compute each child's entropy

    The left side (x5x \le 5) is 5 points, all one class — entropy 00. The right side (x6x \ge 6) is 5 points, 4 of one class and 1 of the other:

    (0.8log20.8+0.2log20.2)0.722-(0.8\log_2 0.8 + 0.2\log_2 0.2) \approx 0.722
  3. Weight the children by size
    510(0)+510(0.722)=0.361\frac{5}{10}(0) + \frac{5}{10}(0.722) = 0.361
  4. Subtract from the parent for the information gain
    0.9710.3610.610 bits0.971 - 0.361 \approx 0.610 \text{ bits}

    The largest of any threshold this dataset admits, even though the right side still isn't perfectly pure.

Checkpoint

Drag the split until information gain reaches within 0.03 bits of the best possible split — 0.610 bits.

Split at 3.0 — information gain = 0.171 bits
Drag the split line to try it
Summary
IG=H(parent)(nLnH(left)+nRnH(right))\text{IG} = H(\text{parent}) - \left(\frac{n_L}{n}H(\text{left}) + \frac{n_R}{n}H(\text{right})\right)

A tree grows by repeating this one move at every node: try every threshold, measure how much entropy it removes, keep the best. Nothing here is new math — it's the same entropy formula from before, just applied twice and subtracted.