Exercises — Random forest algorithm
Level 1 — Recognition
Exercise 1.1
Which of these is the property that makes a random forest different from plain bagging? (a) Bootstrap sampling of rows, (b) averaging tree votes, (c) random feature subset at each split, (d) growing deep trees.
Recall Solution
(c). Plain bagging already does (a), (b), and usually (d). The defining extra is the random feature subset considered at each split, which de-correlates the trees (lowers ).
Exercise 1.2
For a classification forest with features, what is the common default number of features tried at each split? Give the number.
Recall Solution
Rule of thumb . Here . So .
Exercise 1.3
Roughly what fraction of the training rows are out-of-bag (OOB) for any single tree (large )?
Recall Solution
, so about of rows are OOB per tree.
Level 2 — Application
Exercise 2.1
One tree has prediction variance and the average pairwise correlation is . Compute for trees, then for .
Recall Solution
Plug into .
- : .
- : the second term , leaving the floor .
So even infinite trees cannot beat variance — that floor is set by .
Exercise 2.2
Same , , but feature subsampling drops the correlation to . Compute the new and the new floor. Compare with Exercise 2.1.
Recall Solution
- : .
- Floor: .
Lowering from to dropped the achievable floor from to — a 5× improvement that no amount of extra trees could have delivered. This is the variance-reduction engine of RF.
Exercise 2.3
A dataset has rows. Compute the exact probability a specific row is OOB for a bootstrap sample of size 5, and compare to .
Recall Solution
Each of the 5 draws misses the target row with probability ; draws are independent: Compare . Small gives a slightly lower fraction; the limit is approached from below as grows.
Level 3 — Analysis
Exercise 3.1
Starting from the variance-of-a-sum rule, derive . Label WHAT and WHY at each step.
Recall Solution
Step 1 — split the variance of a sum. For , WHAT: wrote the variance of a sum as diagonal (own variances) plus off-diagonal (all covariance pairs). WHY: this is the definition of variance applied to a sum — nothing assumed yet.
Step 2 — use identical variance and correlation. Each (there are of them). Each covariance pair equals (there are ordered pairs, since correlation ): WHAT: replaced every abstract with the single number and every with the single number , then counted how many of each there are ( diagonal, off-diagonal). WHY: the trees are identically distributed (same variance) and share one common pairwise correlation, so we can count identical terms instead of tracking separate ones.
Step 3 — divide by and simplify. Because and with : WHAT: pulled the out front as and distributed it over both counted terms. WHY divide by : the average multiplies the sum by , and variance scales by the square of any constant factor, so becomes — this is the only way to turn the variance of the sum into the variance of the average. Now rewrite : WHY rewrite as : this algebraic step separates the correlation contribution into a -independent floor (, from the constant ) plus a decaying remainder (, which merges with into ). Without this rewrite the floor and the decaying part stay tangled together and the punchline is hidden. WHAT IT LOOKS LIKE: the figure below plots exactly this split — a flat amber floor () plus a cyan decaying piece that dies as grows.

Figure — reading the two pieces. The cyan curve is the total for . The dashed amber line is the floor : notice the cyan curve flattens onto it and never dips below — that is the algebra of Step 3 made visible. The gap between the two curves at any is precisely the term, which is why more trees only close that shrinking gap, never the floor.
Exercise 3.2
Using the formula, find the smallest number of trees such that is within of its floor. Take , (as in Exercise 2.2).
Recall Solution
Floor . "Within " means the extra term . So trees. Interpretation: a couple hundred trees essentially exhausts the benefit of adding more — matching the "diminishing returns plateau."
Exercise 3.3
Two forests A and B have the same . Forest A: , . Forest B: , . With , which forest has lower variance? What lesson does this teach?
Recall Solution
- A: .
- B: .
Forest B wins () despite having 10× fewer trees. Lesson: lowering beats piling on trees. A's floor () is already worse than B's total variance.
Exercise 3.3b
Two forests A and B have the same . Forest A: , . Forest B: , . With , which forest has lower variance? What lesson does this teach?
Recall Solution
- A: .
- B: .
Forest B wins () despite having 10× fewer trees. Lesson: lowering beats piling on trees. A's floor () is already worse than B's total variance.
Level 4 — Synthesis
Exercise 4.1
You are told a forest's OOB error keeps improving as you raise (features per split) from toward , on a very noisy dataset. Reconcile this with "small lowers , which is good." What is the hidden tradeoff, and which vault concept governs it?
Recall Solution
There are two competing effects as changes:
- Small → trees forced onto different features → lower → lower variance floor. (good)
- Small → at each split the tree is only allowed to see a random handful of features, so with high probability the truly predictive feature is not among the candidates at many nodes. The tree is then forced to split on weaker, noisier features. This has two consequences per tree: its splits are less aligned with the true signal, so it fits the signal worse (higher bias), and because which weak feature it lands on is itself random from node to node, its predictions swing more from one bootstrap sample to the next (higher ). Concretely, here is the variance of one tree's prediction across resamples; starving the tree of the good feature makes that prediction more erratic, so rises. (bad)
On very noisy data the signal is fragile; too-small makes individual trees too weak (effect 2 dominates), so raising can improve OOB error even though rises. This is precisely the Bias-Variance Tradeoff playing out through : you tune to balance de-correlation (lower ) against per-tree strength (lower bias and ). Use Cross-Validation or the free OOB error to pick .
Exercise 4.2
Explain, using the variance law, why a random forest reduces variance but a gradient boosting ensemble instead reduces bias. Link to the relevant vault notes.
Recall Solution
- Random forest builds trees in parallel and independently, then averages. The averaging is exactly the mechanism: it drives down variance. So each tree is deliberately low-bias / high-variance (deep, unpruned), and averaging cleans up the variance. See Bagging (Bootstrap Aggregating).
- Gradient boosting builds trees sequentially, each new tree fitting the residual errors of the current ensemble. That fixes systematic under-fitting → it reduces bias. Its base learners are typically shallow (high-bias / low-variance), the opposite choice. See Gradient Boosting.
One sentence: RF averages many strong-but-jittery trees to kill variance; boosting stacks many weak-but-steady trees to kill bias.
Exercise 4.3
A colleague ranks features by Mean Decrease in Impurity (MDI) and finds a high-cardinality ID-like column ranks #1. Why might MDI be misleading here, and what more reliable measure would you use? Reference the relevant note.
Recall Solution
MDI sums the impurity reduction (Gini/entropy drop) a feature causes across splits. A high-cardinality feature (many distinct values) can slice the data into tiny near-pure buckets, producing large apparent impurity reductions even on noise — it is biased toward such features. A more reliable measure is permutation importance: shuffle the feature's values and measure the drop in OOB accuracy. If the ID column were truly useless, shuffling it wouldn't hurt OOB accuracy, exposing MDI's inflation. See Feature Importance.
Level 5 — Mastery
Exercise 5.1
Design a scenario where adding more trees to a random forest does not help at all, then propose two concrete changes that would help. Justify each with the variance law and vault concepts.
Recall Solution
Scenario: all trees are already highly correlated — e.g. one feature is so dominant that every tree splits on it first regardless of the subset (). Then almost independent of ; the term is already tiny. More trees change nothing.
Fix 1 — lower : shrink (fewer features considered per split) so trees are forced off the dominant feature onto alternative ones; this drops the correlation and hence the floor . Grounded in de-correlation. Fix 2 — attack (and bias) directly: engineer or remove the single dominant/noisy feature, or gather more training data; both shrink each tree's prediction variance , which lowers the floor multiplicatively (the floor is the product of and , so cutting either factor cuts the floor). Validate any such change with the free OOB error.
Both fixes target the product , which is the only lever left once is large — extra trees only touch the already-vanished term.
Exercise 5.2
Prove that if trees were perfectly independent (), the forest variance behaves like the classic "" law, and interpret why RF can never quite reach this ideal.
Recall Solution
Set in : This is the textbook variance of an average of independent estimators — it as . Why RF can't reach it: real trees are trained on overlapping bootstrap samples of the same dataset and share the same predictive signal, so their predictions are positively correlated (). Feature subsampling reduces but cannot make it — hence a nonzero floor always remains. The gap between (ideal) and (reality) is literally the cost of correlation.
Exercise 5.3
You have . You can afford one of two upgrades: (A) train as many trees (from to ), or (B) engineer features that cut from to (keeping ). Which upgrade reduces more? Show numbers and give the general lesson.
Recall Solution
Baseline (): (A) , : . Reduction from baseline . (B) , : . Reduction from baseline .
(B) wins by a landslide — lowering cut variance by versus for quadrupling trees, roughly a 13× larger improvement. General lesson: once you are past a few hundred trees, the term is already small, so extra trees buy almost nothing; spend your effort on de-correlation (lowering ) — feature engineering, smaller , less-redundant features — because that is the only lever that moves the floor . See figure.

Connections
- Random forest algorithm — parent note; all formulas built there.
- Decision Trees — the base learner being averaged.
- Bagging (Bootstrap Aggregating) — row-sampling half; source of variance reduction.
- Bias-Variance Tradeoff — governs the and pruning choices.
- Gradient Boosting — bias-reducing contrast (Exercise 4.2).
- Cross-Validation — replaced by OOB for tuning.
- Feature Importance — MDI vs permutation (Exercise 4.3).
- Gini Impurity & Entropy — impurity behind MDI.