← Contents Volume VI · Lecture 12

Volume VI · Trees and Committees

12

Splitting on What Matters Most

Every previous model in this course committed, up front, to a global shape — a line, a sigmoid, a Gaussian per class. A decision tree commits to nothing. It looks at whatever data is in front of it, asks the single most useful yes-or-no question it can find, and asks again on whichever half of the data that question left behind.

The mental model

A decision tree makes no global assumption about the shape of the relationship between features and label at all — it keeps asking the single most useful yes/no question it can find, on whatever data is left, until it runs out of useful questions to ask.

The mechanism

Formalised as CART — Classification and Regression Trees, following Breiman, Friedman, Olshen and Stone — the algorithm is a recursion with one greedy step repeated at every node. At the root, consider every feature and, for each feature, every possible threshold that could split the data into two groups. For each such candidate split, measure how much it reduces impurity across the two resulting child nodes compared with the impurity of the parent. Choose whichever single split reduces impurity the most, partition the data accordingly, and recurse on each child exactly the same way — considering every feature and every threshold again, from scratch, on whatever subset of the data now sits at that node.

Recursion stops at some stopping criterion: a maximum tree depth, a minimum number of examples remaining at a node, or a node whose examples are already pure enough that no split would help. Nothing about this procedure looks ahead — each split is chosen to be the best available right now, with no consideration of how it constrains splits two or three levels further down. That greediness is both the entire source of the algorithm's simplicity and, as the closing section argues, the entire source of its main weakness.

GREEDY RECURSIVE SPLITTING x₁ > 4? yes no x₂ > 1? x₃ > 2? class A class B class A class B
Figure 12a A tree three levels deep. Each internal node is a single feature-threshold question chosen to reduce impurity the most at that node; each leaf reports the class that dominates whatever examples ended up there.

Measuring impurity

"Reduces impurity" needs a number to be greedy about. The CS229 notes give cross-entropy as the splitting criterion: for a region R containing examples from C possible classes, let p̂c be the fraction of examples in R belonging to class c, and define:

Cross-entropy loss Lcross(R) = − Σcc log₂ p̂c

A region containing only one class has p̂c = 1 for that class and 0 for every other, and the sum evaluates to zero — perfectly pure, zero impurity. A region split evenly across classes has every p̂c away from 0 and 1, and the sum is large — maximally impure. A candidate split is scored by how much this quantity drops, weighted by size, going from the parent region to its two children; the split chosen at each node is whichever one drops it the most.

Gini impurity is mentioned in the CS229 notes as a closely related alternative criterion. Its standard form — stated here as the standard form, since it was not verbatim-confirmed from the fetched source this session — is:

Gini impurity, standard form LGini(R) = Σcc(1 − p̂c)

Both criteria are zero exactly when a region is pure and positive whenever classes are mixed together; which one a particular implementation uses rarely changes the resulting tree by much, since both are measuring the same underlying idea of "how mixed is this region" from slightly different angles.

The weakness this creates

A single tree grown deep enough to keep splitting until every leaf is pure will fit its training set almost exactly — impurity driven to zero everywhere. That is precisely the high-variance failure mode named in Lecture 9. Because each split is chosen greedily from whatever examples happen to be in the current region, a small change in the training data — a handful of examples added, removed, or reweighted — can alter an early split, and altering an early split changes which examples reach every node beneath it. The tree that results can look substantially different from the one grown on a near-identical sample, even though the underlying relationship being learned has not changed at all.

SAME DISTRIBUTION · TWO SAMPLES · TWO DIFFERENT TREES tree A, sample A x₁ > 4? x₂ > 1? class B tree B, sample B (overlapping) x₃ > 2? class A x₁ > 5?
Figure 12b Two trees, grown from two overlapping but not identical training sets drawn from the same distribution, disagree at the root split itself — one splits on x₃, the other on x₁ — and everything beneath diverges from there. This is Lecture 9's high-variance end of the trade, made concrete in a model this course has not yet used.

What the next lecture does about it

The obvious fix — constrain each individual tree more tightly, with a smaller maximum depth or a larger minimum-examples-per-leaf — trades away exactly the flexibility that made trees worth using. The next lecture takes the opposite approach: instead of restraining one tree, grow many different trees and combine their predictions.

Read the primary source