Log inStart free
LESSON 4.21 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Growing and pruning trees

Watch a tree split two moons, grow too deep, and get pruned back.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 4.21 · TREE BAY1 LEAF · MEAN 0.5 · TRAINING MSE 0.25
01
Stage 1 of 6 · Predict the mean
Each dot has y = 1 and each square has y = 0. A regression tree starts as one leaf that predicts their mean.
Explain it simply

You see 40 points from two moons. Each dot gets the number 1, and each square gets 0. Before any question, the best single guess is the mean, 0.5: the share of dots, 20 of 40. Gradient boosting later fits trees like this one to the errors of earlier trees.

40 training points, 20 dots and 20 squares. One leaf covers the plane and predicts 0.5. The training MSE is 0.25.

points: dot y = 1, square y = 0split, g and αleaf share of dotserror, missed held-out pointcut by pruning
−1012−101x₁x₂training points: dot y = 1, square y = 0treeMSE by max depth00.10.20.314710leaves0.520/40trainingd01 leaf · depth 0training MSE 0.25−1012−101x₁x₂training points: dot y = 1, square y = 0treeMSE by max depth00.10.20.314710leaves0.520/40trainingd01 leaf · depth 0training MSE 0.25
Toy: two moons (4.C1) · 40 training points, y = 1 dot, 0 square · 1000 held-out points
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
y^=1n∑iyi=n1n,MSE=1n∑i(yi−y^)2\sy{yh}{out}{\hat y} = \tfrac{1}{n}\textstyle\sum_i \sy{y}{data}{y_i} = \tfrac{n_1}{n}, \quad \sy{mse}{grad}{\text{MSE}} = \tfrac{1}{n}\textstyle\sum_i (y_i - \hat y)^2
y^=2040=0.5,MSE=1040=0.25\hat y = \frac{20}{40} = 0.5,\quad \text{MSE} = \frac{10}{40} = 0.25

The leaf predicts the mean, which is the share of dots.

Common mix-ups

MYTHA deeper tree always predicts new points better.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01At full depth, what is the training MSE?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.