Worked examples — Random forest algorithm
Everything here uses only three formulas from the parent, re-stated in plain words before use:
Each symbol will be pinned to a picture before we compute with it.
The scenario matrix
Before solving, let us list every case class a random-forest problem can be. Each worked example below is tagged with the cell it fills.
| # | Case class | What is extreme / tricky | Example |
|---|---|---|---|
| A | = 0 (fully de-correlated trees) | best case, variance drops like | Ex 1 |
| B | = 1 (identical trees) | worst case, variance never drops | Ex 2 |
| C | typical + effect of raising | the realistic middle | Ex 3 |
| D | limiting behaviour | the irreducible floor | Ex 4 |
| E | degenerate (one tree) | forest collapses to a single tree | Ex 5 |
| F | OOB fraction for small vs large | tiny data vs the limit | Ex 6 |
| G | Classification vote incl. a TIE | odd vs even , tie-break | Ex 7 |
| H | Regression average | continuous target | Ex 8 |
| I | Real-world word problem | choosing to hit a variance target | Ex 9 |
| J | Exam twist: "how much did feature-subsampling help?" | compare bagging ( high) vs RF ( low) | Ex 10 |
The variance law is a straight line if we treat as the horizontal axis. Fixing that picture in your head kills cases A–E at once:

Look at the figure. The height where each line lands on the right edge (as , i.e. infinite trees) is — the floor. The steepness of each line is — how fast more trees help. Keep referring back to this as we do the numbers.
Case A — fully de-correlated trees ()
Step 1 — write the tool. Use variance law (1). Why this step? We are asked for the variance of the averaged forest, which is exactly what formula (1) computes.
Step 2 — substitute . The first term , so Why this step? With no correlation the floor collapses to zero — the picture's line ends at height on the right edge. All that survives is the term, the classic "averaging independent things divides variance by " result.
Verify: , which is . Averaging independent estimators divides variance by — matches the textbook independent case exactly. ✓
Case B — identical trees ()
Step 1 — substitute into law (1). Why this step? When the second term's numerator , so the number of trees is irrelevant. In the picture, this is the flat horizontal line — its slope .
Step 2 — interpret. : the forest is exactly as jittery as one tree. Averaging identical clones does nothing. Why? Averaging cancels disagreements, and identical trees never disagree.
Verify: . This is the parent note's punchline made numeric — the variance floor is , and here we already sit on it. ✓
Case C — realistic middle, and turning up
Step 1 — case (a), . Law (1): Careful: . So . Why this step? We plug the given numbers straight in; the is the floor , the is the shrinkable part.
Step 2 — case (b), .
Step 3 — how much did we gain? From to , a drop of . But the floor is , so we can never go below it no matter how many trees. Why this matters: in the picture we slid leftward toward the floor line but the gap to only shrank by — diminishing returns, exactly the "more trees can't beat the floor" lesson.
Verify: floor ; both answers exceed it () and decrease with . ✓
Case D — the limit
Step 1 — take the limit of the second term. As , . Why this step? A fixed numerator divided by a number growing without bound goes to zero — that is what "limit as " means; in the picture , so we read off the right-edge height.
Step 2 — what remains.
Verify: equals the floor we predicted in Ex 3, and Ex 3(b)'s answer is already close, sitting just above it. ✓ The sequence approaches from above and never crosses it.
Case E — degenerate forest, one tree ()
Step 1 — substitute . Why this step? makes the denominator , so the whole second term stays.
Step 2 — simplify. The terms cancel: Why this matters: with one tree there is nothing to average, so the "forest" variance must equal a single tree's variance. The formula passes this sanity test — a great way to remember it is right.
Verify: , correct regardless of . A one-tree forest is a tree. ✓
Case F — OOB fraction: tiny data vs the limit
Step 1 — tool. Use OOB formula (2): . Why this tool and not another? Each bootstrap draw independently misses a fixed row with probability ; over independent draws we multiply, giving the -th power.
Step 2 — (a) .
Step 3 — (b) .
Step 4 — (c) the limit. . Why this step? This is the classic definition of ; small gives a slightly smaller fraction, converging up to .
Verify: — the fraction rises monotonically toward , matching the parent's claim. ✓
Case G — classification vote, including a TIE
Picture six ballot boxes; count the 1's and 0's. This is the discrete cousin of "averaging" — the class with more votes wins.
Step 1 — (a) count. Votes for : positions 1,2,4 → three ones. Votes for : two. , so predict class 1 (sick). Why this step? Majority vote = argmax of the class counts; with (odd) there is always a strict winner.
Step 2 — (b) the tie. Now ones and zeros. There is no majority — the definition breaks. Why this happens: with even a tie is possible. Standard tie-break rules: (i) predict the class with the higher summed probability, or (ii) default to the majority class in training, or (iii) sklearn picks the lowest class label (here ). Using rule (iii): predict class 0.
Verify: count of ones , zeros ; confirms the tie in (b), while confirms class 1 in (a). ✓ Lesson: use an odd to avoid ties in binary classification.
Case H — regression, plain average
Step 1 — tool. Regression forests average (formula 3), not vote. Why this tool? The target is continuous, so "most common value" is meaningless; the mean minimizes squared error across the trees.
Step 2 — compute. So the forest predicts $230{,}000.
Verify: sum , divided by gives ; it lies between the min and max , as any average must. ✓
Case I — real-world word problem: choosing
Forecast: the floor is . Since , the target is reachable. Now find .
Step 1 — set up the inequality. We need Why this step? Subtract the floor from both sides; only the shrinkable term must fit under the remaining budget .
Step 2 — solve for . So trees suffice (the smallest integer is itself).
Step 3 — sanity check the floor. If the SLA had demanded , no would work, because you cannot dip below the floor ; you'd have to lower instead (more feature subsampling). Why this matters: this is the parent's "you're stuck at " lesson turned into a design decision.
Verify: at : ✓. At : ✗. So is exactly the smallest. ✓
Case J — exam twist: how much did feature-subsampling buy?
Step 1 — bagging variance.
Step 2 — random-forest variance.
Step 3 — attribute the improvement. Total drop .
- The floor dropped from to , i.e. of improvement came from lowering .
- The terms actually rose slightly () because grew when shrank — a tiny offset.
- Net: . ✓
Why this matters: essentially 100% of the win came from de-correlation, not from the number of trees. This is the parent's headline — "the real magic isn't more trees, it's lowering " — proven with numbers.
Verify: ; floor change ; -term change ; . ✓
Active Recall
Recall With
, , , what is ? (Ex 1) — pure , the independent case.
Recall Why does
make more trees useless? (Ex 2) The slope : the line is flat, variance stays at the floor .
Recall Smallest
to hit when ? (Ex 9) , from . The floor makes reachable.
Recall OOB fraction for
vs the limit? (Ex 6) vs ; it rises toward the limit.
Recall What fraction of RF's variance win over bagging came from lowering
? (Ex 10) Essentially all of it: floor dropped out of a net gain.
Connections
- Random forest algorithm — the parent theory these examples exercise.
- Bagging (Bootstrap Aggregating) — the high- baseline in Ex 10.
- Bias-Variance Tradeoff — the variance we keep computing.
- Cross-Validation — what OOD/OOB (Ex 6) replaces for free.
- Decision Trees — the single tree that Ex 5 collapses to.
- Feature Importance · Gini Impurity & Entropy · Gradient Boosting — neighbouring topics.