A fully grown decision tree memorizes the training set and shatters on new data. Pruning is the disciplined rollback that trades a little training accuracy for a lot of test accuracy.
Why grow then prune. Greedy recursive binary splitting picks the best split locally at each node. A split that looks weak now may enable a strong split below. So you grow a deliberately large tree (each leaf hits a minimum size, say 5 observations), then prune back. Stopping early (pre-pruning) is short-sighted: it kills good descendants because their parent looked uninformative.
Cost-complexity criterion. Define training-set risk : for regression, residual sum of squares; for classification, misclassification rate weighted by node size. The penalized criterion is:
keeps the full tree . As climbs, branches drop off because each terminal node now costs units of penalty. Eventually only the root survives.
KEY: is the price of a leaf, measured in the same units as . One extra leaf has to reduce by at least to be worth keeping.
Common mistakes
- Searching all subtrees. Cost-complexity pruning is not exhaustive. Weakest-link pruning visits only candidates because the optimal subtrees are nested. Brute-force search wastes compute and earns no extra accuracy.
- Using Gini for the prune step. Gini and cross-entropy grow the tree well but exaggerate impurity gaps for the prune decision. Switch to misclassification rate when computing for cost-complexity pruning on classification trees.
- Picking on the training set. Training error is monotone decreasing in , so it always prefers with . You must use cross-validation or a held-out validation set, never re-substitution error, to select .
Bottom line
- Why prune: a fully grown tree has low bias and explosive variance; pruning collapses high-variance leaves to lower test error.
- Grow a deliberately large tree first, then prune. Pre-pruning is myopic because it stops on locally weak splits that enable strong later ones.
- Cost-complexity pruning minimizes , where is the number of terminal nodes and is the complexity penalty.
- Weakest-link pruning yields a nested sequence , collapsing the node with smallest first.
Exam shortcut
If a question gives you the nested sequence and an , find the largest with and return . Do not interpolate. If a question lists subtree risks and asks which collapses first, compute for each candidate and pick the smallest.
The full lesson (about 2,180 words, 15 min read) adds 2 worked examples, all 6 common mistakes, a self-check, free in the app.
Learning objectives
- C2
Browse all free MAS-II lessons or jump into free MAS-II practice questions.