2.3.4 · D1Tree-Based & Instance Methods

Foundations — Tree pruning techniques

2,025 words9 min readBack to topic

This page assumes nothing. Before you touch cost-complexity pruning on the parent note, you need to genuinely see what a tree, a leaf, an error, and a penalty knob are. We build each symbol from a picture, in an order where every piece rests on the one before it.


0. The picture everything lives in: a decision tree

Every symbol on the parent page is a label attached to a part of one drawing — a tree of yes/no questions. So let's draw it first and name its parts.

Figure — Tree pruning techniques

WHY do we care about this vocabulary? Because pruning is literally an operation on this picture: cut the branches under some internal node, and that node becomes a leaf. Everything else is bookkeeping about which node to cut. If trees are new to you, build them first with Decision Trees (CART).


1. A data point and its "true label"

Before a tree can be right or wrong, we need something for it to be right or wrong about.

When a dot slides down and lands in a leaf, the leaf guesses a label. Two things can happen: the guess matches the true label (correct), or it doesn't (a mistake). That mismatch is the seed of error, which we define next.


2. Error at a leaf:

Here is the first real symbol from the parent: .

Figure — Tree pruning techniques

WHY this exact quantity? Because pruning is a bargain — "cut some branches, pay a little more error." To talk about paying error, we first need a number that measures error. is that number, per box. (The "impurity" flavour of — Gini or entropy instead of raw miscount — is exactly Gini Impurity & Entropy; same role, smoother measure.)


3. Counting leaves: and

Two symbols that look scary but mean something you can count on your fingers.

The bars always mean "how many / how big". So is literally: count the bottom boxes.


4. A subtree: and

Pruning doesn't chop the whole tree — it chops one branch's worth. So we need a name for "the piece hanging below one node."

Figure — Tree pruning techniques

WHY is (collapsing never lowers training error)? Because the subtree had extra questions to separate the dots; throwing them away can only blur things. So the numerator of the effective-alpha formula is always — the extra error you accept by cutting. This is why you must never judge pruning on training data (see Cross-Validation): training error alone always votes "keep everything."


5. The penalty knob:

Now the star symbol: (the Greek letter alpha, just a name for a number you dial).

Figure — Tree pruning techniques

6. The one inequality you'll see solved

The parent rearranges "prune when B is no worse than A." You just need to be comfortable that manipulating an inequality is like a see-saw: do the same thing to both sides.

One caution the parent flags: we divide by , so this only makes sense when the subtree has more than one leaf (). A node whose subtree is already a single leaf isn't an internal node to prune — no division-by-zero ever happens.


How the foundations feed the topic

data point + true label

error at a leaf R of t

total tree error R of T

count the leaves size of T tilde

subtree T sub t and its leaf count

cost-complexity R alpha = R of T plus alpha times leaves

penalty knob alpha

effective alpha of a node

weakest-link pruning: cut cheapest alpha first

pick best alpha by cross-validation

Each arrow is a "you need this before that." Notice cross-validation sits at the very end: once foundations give us a sequence of trees indexed by , Cross-Validation is how we choose which one generalizes best — and a whole forest of such trees is Random Forests.


Equipment checklist

Cover the right side; say it out loud; then reveal.

What is a leaf of a decision tree?
A bottom box with no branches below it — it stops asking questions and just predicts a class.
What does measure?
How wrong a single node is — the fraction of its data points it labels incorrectly (0 if the node is pure).
What does equal in terms of leaves?
The sum of over every leaf: .
What is ?
The number of leaves — our measure of the tree's complexity/size.
What is the subtree ?
The mini-tree hanging below node : that node plus all its descendants down to their leaves.
When you prune at , how many leaves do you remove?
(all of the subtree's leaves except the single leaf becomes).
What does represent, in plain words?
The price you pay in extra training error for each leaf you keep — an exchange rate between size and accuracy.
Why does bigger give a smaller tree?
taxes each leaf, so a higher tax means fewer leaves survive; keeps the full tree, leaves only the root.
Why is always ?
Collapsing a subtree removes questions that separated the data, so training error can only stay equal or rise.
What is in words?
Extra error per leaf saved by cutting node : — the node with the smallest value is pruned first.