Visual explainer
Random Forests
Track six rows through replacement sampling, per-node feature choices and three tree routes. Compare voting with probability averaging, inspect OOB coverage and expose shared mistakes.
A random forest combines trees trained with randomized rows and feature candidates. Combining their predictions can reduce sensitivity to one fitted tree; agreement does not establish truth. Here the same query x = 3.25 lands on different sides of two fitted cuts: T1 predicts B and T2 predicts A.
Our synthetic dataset has six rows with IDs 1 through 6 and labels A, A, A, B, B, B. Five numeric features use arbitrary units: x and z both equal the row ID, while u, v and w are zero. Circles represent A, triangles B; numbers identify rows. The first scene projects onto x, with identical scales in both strips.
Freeze three replacement bags: T1 = [1,2,2,4,5,5], T2 = [1,3,3,4,6,6], T3 = [2,3,4,4,5,6]. With candidate features , T1 separates its pure leaves at x ≤ 3, the midpoint between its largest A value 2 and smallest B value 4. T2 considers and splits at x ≤ 3.5, between 3 and 4. These hand-checked illustrative fits produce the differing query predictions; no library execution or test-error measurement is claimed.
Draw With Replacement
The upper row is the original pool. The lower row records six T1 draws in order, with duplicate IDs 2 and 5 bracketed. Replacement makes a row available again after selection. The bag has six draws but only four unique rows; rows 3 and 6 remain in the dataset even though T1 never trains on them.
Different Trees Omit Different Rows
Read one bag across the six ID columns. A check means the row occurs at least once, while a hollow circle means it is absent. The matrix records membership, not duplicate counts. T1 omits , T2 omits , and T3 omits . Row 4 appears in every bag.
A specified row has probability (5/6)⁶ ≈ 0.3349 of being absent from a full six-draw bag: each draw independently avoids it with probability 5/6. The familiar 1/e ≈ 0.3679 is the large-dataset limit of (1 − 1/N)ᴺ, not the exact answer for N = 6. Omitted rows form a different out-of-bag group for each tree.
Resample Features at Each Node
This schematic shows the feature-search mechanism, separate from our already-pure stumps. A root considers ; a later child might consider . The small unlabelled sibling is outside this detail view. A candidate subset is sampled anew at each split node, then eligible feature thresholds compete by impurity. Two features from five is a chosen illustration, not a universal setting.
The three fixture stumps stop after their root because their leaves are pure; none needs the schematic child split. Feature randomness can diversify fitted rules, but does not guarantee independent errors. The official forest guide describes both sources of randomization.
Send One Query Through Three Trees
Return to the frozen bags. T3 considers and splits at z ≤ 3.5, separating A rows 2 and 3 from B rows 4, 5 and 6. All three trees have pure A leaves on yes branches and pure B leaves on no branches.
For the new query x = 3.25, z = 2, u = v = w = 0, T1 evaluates 3.25 ≤ 3 as false and returns B. T2 evaluates 3.25 ≤ 3.5 as true and returns A. T3 evaluates 2 ≤ 3.5 as true and returns A. Emphasized paths are used; dashed branches are not. The query lies off the x = z pattern in the training rows, and its true label is unknown. These trees are parallel predictors, not rounds correcting earlier trees.
Combine the Outputs
Each tree contributes one class vote. The lower tally preserves B, A, A, and brackets the two A votes, so hard voting predicts A. No individual tree is declared wrong: the query's truth remains unknown.
The original random-forest classifier uses class voting. Scikit-learn instead averages leaf class probabilities. For these pure leaves, P(A) is [0,1,1], so the average is (0 + 1 + 1)/3 = 2/3; both conventions choose A here.
Mixed Leaves Change the Convention
Switch to a separate leaf-output example, not the pure stumps above. Leaves 1 and 2 each contain 2 A and 1 B; leaf 3 contains 0 A and 2 B. Their P(A) values are [2/3,2/3,0]. Bars use the same probability scale; the third leaf is a zero-length tick. The dashed line marks the binary choice boundary at 0.5.
Hard labels are A, A, B, giving an A majority. Probability averaging gives P(A) = (2/3 + 2/3 + 0)/3 = 4/9 ≈ 0.4444 and P(B) = 5/9, so it predicts B. The mean bar ends before 0.5. The aggregation convention matters; these leaf frequencies do not establish calibrated confidence or tell us which prediction is correct.
Shared Variation Remains
This is a conditional scalar-averaging calculation, not measured classification error or the preceding class fixture. Assume B equally variable tree outputs, each with variance σ², and every pair has correlation ρ. Summing B variance terms and B(B − 1) covariance terms, then dividing by B², gives:
Set σ² = 1 and ρ = 0.25. For B = 1, 3, 10 and 100, total variances are 1, 0.5, 0.325 and 0.2575. Each hatched lower segment is the same 0.25 shared component; the upper segment is 0.75/B. The final upper segment is intentionally very thin. Adding trees shrinks the latter term, leaving the former.
This does not supply a universal tree count or a test-error curve. Larger forests cost memory and prediction work. Choose their size using validation behavior and resource constraints; a finite average of axis-aligned constant leaves is still piecewise constant, even when its boundaries become more detailed.
Validate Each Row With Eligible Trees
Return to the six training rows. T1 and T3 trained on row 2, so their paths stop at crosses. Only T2 omitted it: evaluate row 2's x = 2 through T2, which predicts A. That is row 2's OOB prediction and agrees with its known label. Row 4 has no eligible tree yet, so it has no OOB prediction in this miniature forest.
An OOB estimate combines eligible predictions separately for each row and compares them with the known label. Report coverage as well as mistakes; an uncovered row is not automatically correct. More trees can add eligible predictions, but three trees here do not provide complete coverage, and OOB evaluation does not remove the need for an appropriate final evaluation design.
Where It Breaks
Use a new counterexample with x = z = 2.25 and stipulated true class B. The same three stumps all take yes branches because 2.25 ≤ 3 and 2.25 ≤ 3.5. Their pure A leaves combine into the wrong A prediction; the triangle identifies the actual B label. Unused branches are omitted for focus.
Repeating these three outputs six or sixty times would still predict A. Randomized training cannot guarantee recovery when errors are shared. Label noise or a missing informative feature can produce this kind of failure. This is a constructed counterexample, not a claim that correlated input features always force a forest to fail, or that every additional randomized tree must repeat the same mistake.
The Quick Version
- Replacement bags can move a tree's fitted threshold.
- A full-size bag can repeat rows and omit others.
- Each tree has its own out-of-bag rows.
- Candidate feature subsets are sampled again at split nodes.
- One query can reach different leaves across trees.
- Combining outputs produces a prediction, not proof of correctness.
- Hard voting and probability averaging can disagree on mixed leaves.
- Shared variation limits the benefit of scalar averaging.
- OOB predictions exclude trees trained on the evaluated row.
- Repeating shared errors does not repair the wrong prediction.