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

Bagging and random forests

Watch many shaky trees vote, and see their wobbles cancel out.


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.22 · FOREST BAY5 LEVELS · 10 LEAVES · TEST 79%
01
Stage 1 of 6 · One deep tree
A decision tree grown to pure leaves fits all 40 points. On 1000 new points it scores 79%.
Explain it simply

The points form two moons: the squares are class 0, and the dots are class 1. One tree keeps splitting until each box holds one class. It gets every training point right, but its small boxes chase noise. On 1000 new points it scores only 79%.

One tree with 10 leaves, 5 levels deep. Training accuracy 100%, test accuracy 79.2%.

points: dot class 1, square class 0split threshold, tree countregion and votes for class 1, accuracyGini impurity, correlation ρpoint left out
−1012−101x₁x₂one deep tree, all 40 pointsthe treex₂x₂9x₂14x₂x₁4x₂x₁125x₂x₂3110train 40/40 = 100% · test 792/1000 = 79.2%5 levels · 10 leaves−1012−101x₁x₂one deep tree, all 40 pointsthe treex₂x₂9x₂14x₂x₁4x₂x₁125x₂x₂3110train 40/40 = 100% · test 792/1000 = 79.2%5 levels · 10 leaves
Toy: two moons · 40 training points · 1000 test points · seeded
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
acc=#{y^=y}n\text{acc} = \frac{\#\{\sy{yhat}{out}{\hat y} = \sy{y}{data}{y}\}}{\sy{n}{data}{n}}
train: 4040=100%,test: 7921000=79.2%\text{train: } \tfrac{40}{40} = 100\%,\quad \text{test: } \tfrac{792}{1000} = 79.2\%

Accuracy is the share of points that the tree gets right.

Common mix-ups

MYTHMore trees make a forest overfit.

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

Predict, then reveal
3 CHECKS · PRO
Q01Which changes more with a new training sample: one deep tree, or a vote of 100?

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.