CART in Depth
Split criteria, cost-complexity pruning, categorical features and missing values.
CART rests on three small theorems: concave impurities never increase under a split, the subtrees that minimize cost-complexity are nested, and the best binary split of a categorical feature lies along one ordering of its levels. This lesson proves all three, explains surrogate splits for missing values, and sets CART beside ID3, C4.5 and the gain ratio.
What you’ll learn
- Prove that concave impurities never increase under a split, characterize when strictly concave ones stay flat, and explain why misclassification error fails as a growing criterion.
- Prove that cost-complexity pruning yields a finite nested sequence of optimal subtrees computed by weakest-link pruning, and select one by cross-validation.
- Prove the ordering theorem for binary splits of a categorical feature in regression and two-class problems, and explain why it fails for three or more classes.
- Explain surrogate splits, ID3's bias toward many-valued attributes, and C4.5's gain ratio.
Concave impurities, and why misclassification fails
Counting examples class by class, the parent's proportions are the mixture of the children's, with weights (both children are nonempty):
Concavity is exactly Jensen's inequality for two points, and it gives ; strict concavity makes the inequality strict unless the two points coincide.
Gini and entropy are strictly concave on the simplex: their Hessians are negative definite in the interior (entropy measured in bits).
Misclassification error is concave (a minimum of affine functions) but affine wherever the majority class is fixed. If both children keep the parent's majority class , the weighted error equals the parent's, whatever happens to the other classes:
For example, a node with 70 examples of class 1 and 30 of class 2 has misclassification error 0.30. Splitting off 35 class-1 examples into a pure child leaves , still with a class-1 majority: the weighted error is , a decrease of exactly zero, although half of the majority class is now settled for good. Gini falls from 0.420 to 0.323, and entropy from 0.881 to 0.647 bits.
A node holds 80 examples of class 1 and 20 of class 2. Which split leaves the misclassification error unchanged?
- and
- and
- and
- and
Show the answer
A. and
In and both children keep the class-1 majority, so the errors are , the same as the parent's 20. In each of the other splits one child switches to a class-2 majority, and the error count falls to 10, 10 and 15 respectively. Gini still rewards the first split: it falls from 0.32 to .
Concavity also governs how fast greedy growth can drive the training error down. Kearns & Mansour (1999) analyzed top-down induction under a weak-learning assumption: at every node, some allowed split function has error at most on a suitably reweighted node distribution. Under it, greedy growth reaches training error with trees of size using the Gini criterion and using entropy, as in C4.5; their new criterion , more sharply curved near pure nodes, needs only , polynomial in . They also note why misclassification error offers no such guarantee: its decrease is nonzero only when the two children have different majority classes, which the weak-learning assumption does not imply. In this precise sense top-down tree growth is a boosting algorithm (Boosting).
Cost-complexity pruning: the nesting theorem
Fix a large tree . A pruned subtree keeps the root and, at each kept node, either both children or neither. Write for its leaves, for the training error of node if it were a leaf, counted as a fraction of all examples so that leaf errors add up, and . The cost-complexity is .
Let be the branch of rooted at and . Because adds over leaves, an optimal pruning of either collapses or prunes the two child branches optimally and independently (for a leaf, ):
Each is the minimum of finitely many affine functions , one per subtree: concave and piecewise linear in , with one-sided slopes equal to leaf counts, so at least 1. Collapsing is (weakly) optimal exactly when the advantage of collapsing is nonnegative:
The two child terms have slopes of at least 1 each, so has slope at least everywhere: it is strictly increasing. The set of at which is collapsed in the smallest optimal subtree (ties broken toward collapsing) is therefore an interval : once pruned, a node stays pruned.
Induct from the leaves up: the smallest optimal subtree of is when , and otherwise the union of its children's, which are nested in by induction. So . Inside , collapsing ties with keeping its branch exactly when , which is the weakest-link formula; the smallest such is the next breakpoint.
Think first A complete binary tree of depth has pruned subtrees, with : either collapse the root, or prune both depth- branches independently. How many does a depth-5 tree have, and how many of them can the weakest-link sequence visit?
, , , and : doubly exponential growth. Yet the weakest-link sequence of a depth-5 tree has at most 32 members, since each step removes at least one of its 32 leaves. The nesting theorem turns an enormous search into a short path.
Selecting . Cross-validation must prune each fold's own tree. For fold , grow on the other folds, prune it at the geometric midpoints of the full-data breakpoints, and score each pruned tree on fold . The with the lowest average error selects from the full-data sequence. The one-standard-error rule, introduced with CART, instead takes the smallest tree whose cross-validated error is within one standard error of the minimum: the curve is usually flat and noisy near its minimum, so a much smaller tree costs little accuracy.
Categorical features: the ordering theorem
The within-level variation is the same for every split, so minimizing over sets of levels means minimizing the weighted within-group sum of squares of the level means. Treat level as a point of weight ; let and be the total weight and weighted mean of group :
Move one level (weight , mean ) from a group of weight and mean to the other group, of weight and mean . Removing a weighted point lowers a group's sum of squares by , and adding one raises it by , so the move changes the objective by
At an optimum no move helps, so . Since , this forces every level (barring exact ties) to lie strictly closer to its own group's mean than to the other's. The groups are separated by the midpoint , so each is a contiguous block of the sorted order. (A single-level group is trivially at its own mean.)
For two classes, the Gini impurity is twice the variance of a 0/1 label, so the weighted Gini of a split is times its SSE on 0/1 labels, and the regression case applies with . Entropy needs a separate argument, given by Breiman et al. (1984).
In a 3-class problem, a library sorts the 6 levels of a categorical feature by and scores only the 5 prefix splits. Is the Gini-optimal binary split guaranteed to be among them?
- Yes: the ordering theorem holds for any number of classes
- Yes, provided the classes are balanced
- No: with three or more classes, the optimal split need not be a prefix of any single ordering of the levels
- No, because Gini cannot be used with categorical features
Show the answer
C. No: with three or more classes, the optimal split need not be a prefix of any single ordering of the levels
The proof places each level at a point on a line. With classes, each level is a point in the simplex , and an optimal two-group partition of points in two or more dimensions need not be cut out by any ordering along one line. Exact search is exponential in , so libraries order levels heuristically, for example along the first principal component of their class-probability vectors (Coppersmith, Hong & Hosking, 1999), or one-hot encode.
A many-level feature also carries a statistical cost. Even after ordering it offers candidate splits, each fitted to the same labels, so a noise feature with many levels finds a good-looking split by chance more often than a binary one, and greedy growth favors it. Conditional inference trees (Hothorn, Hornik & Zeileis, 2006) remove this bias by separating the two questions: a permutation test chooses the variable, and only then is the best split point of that variable found.
Missing values and surrogate splits
CART handles a missing value of the split feature by asking a different feature. Let be the chosen split at node , sending fractions of the node's examples left and right. For every other feature , find the split on that best reproduces where sends the examples (among those with both features observed). The majority rule, sending everything to the larger child, already errs on a fraction ; a surrogate is useful only if it does better:
Surrogates also expose masking. A feature that is never chosen as a primary split, because a correlated feature is always slightly better, can be an excellent surrogate everywhere. CART's original variable importance therefore credits each feature with the impurity decrease of its best surrogate split at every node, not just its primary splits. Other systems handle missing values differently: C4.5 sends the example down every branch with weights proportional to the branch sizes and averages the predictions, and gradient-boosting libraries learn, at each split, the default direction that most reduces the loss for missing values. When missingness itself carries information, treating "missing" as a value of its own can beat any imputation (Missing Data).
ID3, C4.5 and the gain ratio
Quinlan's ID3 (1986) grew multiway trees on categorical attributes: a node splits on one attribute into one child per value, choosing the attribute with the largest information gain. Multiway splits expose a bias. An attribute with a distinct value for every example, such as a customer ID, splits the node into pure singletons and attains the largest possible gain, , while being useless for prediction. Quinlan's remedy, described in the same paper and adopted by C4.5 (Quinlan, 1993), divides the gain by the entropy of the partition itself:
A node has 16 examples, 8 of each class, so bit. An ID attribute gives every example its own value. What is its gain ratio?
Show the answer
0.25
The gain is the full 1 bit, but SplitInfo bits, so GR . A binary attribute splitting the node into and has gain bits and SplitInfo 1, so GR . Raw gain prefers the ID (1 against 0.456); the gain ratio prefers the genuine attribute.
| Algorithm | Splits | Split criterion | Size control | Missing values |
|---|---|---|---|---|
| CART (Breiman et al., 1984) | binary | Gini or twoing; squared error for regression | grow large, cost-complexity pruning chosen by cross-validation | surrogate splits |
| C4.5 (Quinlan, 1993) | multiway on categorical, binary on numeric | gain ratio | error-based pruning with a pessimistic (upper confidence limit) error estimate | fractional examples sent down every branch |
| CHAID (Kass, 1980) | multiway, merging similar categories | chi-squared tests with Bonferroni adjustment | stop when no split is significant | a separate category |
| Conditional inference trees (Hothorn et al., 2006) | binary | permutation tests choose the variable, then the best split point | stop when no test is significant | surrogate splits |
Key takeaways
- Concave impurities never increase under a split (Jensen); strictly concave ones such as Gini and entropy decrease unless the children's class proportions are equal, while misclassification error stays flat whenever both children keep the parent's majority.
- Under a weak-learning assumption, greedy growth is a boosting algorithm whose progress depends on the criterion's curvature (Kearns & Mansour, 1999); misclassification error gives no guarantee.
- , and the advantage of collapsing grows with , so the smallest optimal subtrees are nested and finitely many; weakest-link pruning finds them, and cross-validation (often with the one-standard-error rule) picks one.
- For regression and two-class problems, an optimal binary split of a categorical feature is a prefix of the levels sorted by mean response, so splits suffice; with three or more classes no ordering is guaranteed.
- Surrogate splits route missing values and reveal masked features; ID3's gain favors many-valued attributes, which C4.5's gain ratio corrects.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A split leaves both children with the parent's majority class, but makes one child much purer. Which impurity decrease is guaranteed to be exactly zero?
- Gini impurity
- Entropy
- Misclassification error
- All three
Show the answer
C. Misclassification error
With the majority class fixed, misclassification error is the affine function of the proportions, and the parent's proportions are the weighted average of the children's, so the weighted error is unchanged. Gini and entropy are strictly concave, so they decrease whenever the children's proportions differ.
Why are the smallest cost-complexity-optimal subtrees nested as grows?
- Because the advantage of collapsing a node, , increases with at rate at least 1, so once collapsing is optimal it stays optimal
- Because the training error of a subtree is never larger than that of the full tree
- Because is a convex function of the tree
- Because weakest-link pruning removes exactly one leaf per step
Show the answer
A. Because the advantage of collapsing a node, , increases with at rate at least 1, so once collapsing is optimal it stays optimal
, and each has slope at least 1 (every subtree has a leaf), so has slope at least 1. Collapsing is optimal on an interval , and induction over the tree gives nesting.
A regression tree considers a categorical feature with 8 levels whose mean responses are known. How many binary splits must it score to be sure of finding the optimal one?
Show the answer
D.
By the ordering theorem, some optimal split is a prefix of the levels sorted by mean response, and there are nonempty proper prefixes. Exhaustive search would score all partitions.
Why does C4.5 divide the information gain by the split information?
- To convert bits into a probability
- To penalize attributes that fragment the node into many small branches, which gain information by fragmentation alone
- To make the criterion strictly concave
- To make the tree invariant to monotone transformations of the features
Show the answer
B. To penalize attributes that fragment the node into many small branches, which gain information by fragmentation alone
An attribute with a distinct value per example reaches the maximum gain by splitting into singletons. Its split information, of the number of branches for equal-sized ones, is large, so the ratio exposes it. C4.5 restricts the choice to attributes with at least average gain, to avoid rewarding attributes with tiny split information.
Further reading
- L. Breiman, J. H. Friedman, R. A. Olshen & C. J. Stone, Classification and Regression Trees (Wadsworth, 1984), chapters 3–5 and 10.
- J. R. Quinlan, C4.5: Programs for Machine Learning (Morgan Kaufmann, 1993).
- M. Kearns & Y. Mansour, "On the boosting ability of top-down decision tree learning algorithms," Journal of Computer and System Sciences 58(1), 109–128 (1999).
- T. Hothorn, K. Hornik & A. Zeileis, "Unbiased recursive partitioning: a conditional inference framework," Journal of Computational and Graphical Statistics 15(3), 651–674 (2006).
- W.-Y. Loh, "Fifty years of classification and regression trees," International Statistical Review 82(3), 329–348 (2014).