2.3.4 · D3Tree-Based & Instance Methods

Worked examples — Tree pruning techniques

2,557 words12 min readBack to topic

Before we start, one symbol reminder so nobody is lost from line one:


The scenario matrix

Every question this topic can ask falls into one of these cells. The examples below are tagged with the cell they cover.

# Case class What's special Covered by
C1 Compute for one node the basic "price per leaf" Ex 1
C2 Degenerate: subtree has 2 leaves () denominator , no dividing subtlety Ex 2
C3 Choose the weakest link among several nodes smallest wins Ex 3
C4 flips the keep/prune decision compare at two values Ex 4
C5 Limiting values and full tree vs root Ex 5
C6 Build the full -sequence weakest-link pruning end-to-end Ex 6
C7 Reduced-Error Pruning decisions tie / worse / better on validation Ex 7
C8 Real-world word problem (medical cost trade) translate words → Ex 8
C9 Zero/degenerate: perfectly pure tree () numerator behaviour, still prune? Ex 9
C10 Exam twist: pick from a CV curve U-shape, minimum not extreme Ex 10

We'll fill them in order.


Warm-up figure: what "cost vs size" looks like

Figure — Tree pruning techniques

Look at the picture. The blue curve is (training error): it only ever goes down as you add leaves — a tree with more boxes fits the training data better, always. The orange line is the tax : a straight ramp, steeper for bigger . The green curve is their sum — the bill we actually minimise. Its lowest point is the tree we want. Change (tilt the orange ramp) and the green valley slides left (smaller tree) or right (bigger tree). Keep this image in mind for every example.


Worked examples

Figure — Tree pruning techniques

The figure above is exactly Ex 10: green dots are CV error, dipping into a valley at , while the blue dashed line (training error) slides ever downward and would fool you into keeping the biggest tree.


Quick recall

Recall Which node is pruned first, and why?

The internal node with the smallest — it buys the least accuracy per leaf, so it's the cheapest (weakest) link. ::: smallest formula? ::: At exactly, keep-cost vs prune-cost? ::: they tie Which data selects the final ? ::: Cross-Validation (never training error) Shape of the CV-error-vs- curve? ::: U-shaped — pick the minimum


Connections