2.3.7 · D2Tree-Based & Instance Methods

Visual walkthrough — Random forest algorithm

1,766 words8 min readBack to topic

Read this if the algebra in the parent felt like magic. By the end you will see the floor.

Prerequisites we lean on: Bagging (Bootstrap Aggregating) (the row-sampling that makes many trees), Decision Trees (the wobbly expert we are averaging), and Bias-Variance Tradeoff (why "wobble" is a thing worth killing).


Step 1 — What is "variance", drawn as a spread of darts?

WHAT. Before any formula, pin down the one word everything rests on. A prediction from a tree is not a fixed number — retrain the same tree on a slightly different sample and it gives a slightly different answer. So a prediction is a random variable: a number that jitters around some centre.

Variance is just how wide that jitter is. Write it for a tree's prediction . If we call the average value (the centre of the cloud), then

The square makes every miss positive (left and right misses both count) and punishes big misses more. We name this width , so . The plain letter (its square root) is the typical distance from centre.

WHY this tool. We want to measure "how unreliable is one tree?" Not its bias (is the centre right?) but its shakiness. Variance is exactly the shakiness meter.

PICTURE. Think darts on a board: the centre is , the scatter of the darts is .

Figure — Random forest algorithm

Step 2 — Averaging many independent darts shrinks the spread

WHAT. Now take trees, predictions , and average them: . Here is simply how many trees and (f-with-a-bar) is their mean vote. Suppose for now the trees are independent — their jitters have nothing to do with each other, like darts thrown by strangers in separate rooms.

WHY averaging. When one tree overshoots and another undershoots, the two errors partly cancel. Independence means the cancellations are as good as it gets. The question we are answering: how much steadier is the crowd's answer than one member's?

The rule for independent variables: variance of an average is

Each symbol: is one tree's spread, is the crowd size, and dividing by says the crowd's spread is times narrower. Ten independent trees → one-tenth the variance. A hundred → one-hundredth.

PICTURE. The single-tree dart cloud is fat; the average-of-many cloud is a tight knot around the same centre.

Figure — Random forest algorithm

Step 3 — Correlation: when the darts move together

WHAT. Two trees are correlated when their jitters are linked: if tree overshoots, tree tends to overshoot too. We measure the link between a pair with the covariance — the average of (how far is from its centre) (how far is from its centre). Same-direction misses ⇒ positive; opposite ⇒ negative; unrelated ⇒ zero.

To get a unitless number between and we divide covariance by the spreads, giving the correlation (Greek "rho"):

Reading it: is the shared wobble between any two trees. ⇒ strangers (Step 2's happy case). ⇒ clones (they never disagree). Forests live in between.

WHY this tool. Averaging only cancels errors that disagree. Correlation is precisely the meter for "how much do the trees agree by default" — so it must control how well averaging works. We introduce now because the next step needs exactly this quantity.

PICTURE. Two dart clouds for a pair of trees: strangers scatter in a round blob (); clones line up on a diagonal ().

Figure — Random forest algorithm

Step 4 — The variance of a sum: count the boxes

WHAT. To average, first sum. So compute . The exact rule (the definition of variance applied to a sum) is: add up every tree's own variance, then add every cross-term covariance:

WHY a grid. The cleanest way to see "every pair" is a table where cell holds . The diagonal cells are — a tree with itself. The off-diagonal cells are from Step 3.

Count them.

  • Diagonal cells: there are of them, each → total .
  • Off-diagonal cells: a grid has cells, minus on the diagonal = cells, each → total .

PICTURE. The grid, diagonal shaded one colour (), off-diagonal another () — the whole formula is just counting coloured boxes.

Figure — Random forest algorithm

Step 5 — Divide by to get the average, and read the two terms

WHAT. We wanted , not the sum. Scaling a random variable by a constant scales its variance by ; here , so we divide the whole Step-4 result by :

Split the fraction term-by-term:

Now rewrite and gather:

Term-by-term meaning:

  • — the floor. It has no in it. Adding trees cannot touch it. It is the shared wobble that survives all averaging.
  • — the meltable part. Growing shrinks it toward . Notice when this whole formula collapses to Step 2's — our independent case falls right out, a good sanity check.

PICTURE. A curve of against the number of trees : it drops fast, then flattens onto a horizontal line at height .

Figure — Random forest algorithm

Step 6 — Edge and degenerate cases (never leave the reader guessing)

WHAT. Push the formula to its extremes and read what each says.

PICTURE. Four floor-lines on the same axes, one per case.

Figure — Random forest algorithm
  • (independent trees). Formula → . Floor is : infinitely many strangers do reach perfect steadiness. This is the ideal we can only approach.
  • (clone trees, e.g. no feature randomness on data with one dominant feature). for all , so . Averaging clones gives you one clone — no benefit at all. This is the disaster plain Bagging (Bootstrap Aggregating) risks and why the random feature-subset exists.
  • (a single tree). . Reassuring: "one tree's variance is one tree's variance." The formula is self-consistent at the boundary.
  • . Second term ; variance . The floor, exactly. This is why the parent says "the real magic is lowering , not raising ."

The one-picture summary

Everything on this page in one frame: a fat single-tree cloud → a covariance grid (diagonal , off-diagonal ) → the decay curve landing on the floor .

Figure — Random forest algorithm
Recall Feynman retelling — the whole walkthrough in plain words

One decision tree is like a nervous friend whose answer wobbles depending on which examples she happened to study (Step 1 — that wobble is variance ). Ask a hundred unrelated friends and average their answers, and the wobbles cancel — the crowd is a hundred times steadier (Step 2 — ). But friends who all studied the same book give the same wobble; how alike they are is correlation (Step 3). To find the crowd's wobble exactly, lay every pair in a grid: the diagonal boxes are each friend's own wobble, the off-diagonal boxes are shared wobble, and you just count and add them (Step 4). Divide by the crowd size squared to turn the sum into an average, and the answer splits cleanly into two pieces: a floor that no amount of friends can remove, plus a meltable piece that shrinks as the crowd grows (Step 5). So if the friends are strangers () the floor is zero — but if they're clones () the crowd is no better than one person (Step 6). That is why a random forest doesn't just add trees; it forces each tree to look at different features, pushing down and lowering the floor itself.


Connections