Random Forest
Random Forest — Bag decision trees with random feature subsets.
A random forest takes bagging one step further: each tree not only sees a different sample of the data but also a random subset of features at each split. This decorrelates the trees and makes the forest even more robust.
Tree 1 on its own — sample only
Forest vote — 0 trees
- Class 0
- Class 1
- Out-of-bag (hollow)
One point per tree added. Disagreement is the average vote split across the plane — 0% means every tree already says the same thing everywhere.
Forest controls
The idea in plain words
A random forest takes bagging one step further: each tree not only sees a different resample of the data but also considers only a random subset of features at each split. This decorrelates the trees, so averaging them helps far more.
Out-of-bag error — scoring each point using only the trees that didn’t train on it — gives a free validation estimate. If you let every split see all features, the trees become near-identical and the ensemble stops improving.
Now, the math
Averaging correlated trees only reduces variance so far:
- the correlation between trees — feature subsampling lowers it.
- the variance of a single tree.
▸ Show the derivation
As B → ∞ the second term vanishes but the first, ρσ², remains — so the only way to keep reducing variance is to lower ρ. Restricting each split to a random feature subset does exactly that, at the cost of a little more bias per tree. Using all features sends ρ → 1 and erases the benefit.
Trace it by hand
Let us put real numbers into the variance formula. Dataset: 16 points in two overlapping blobs (class 0 around (3.5, 3.5), class 1 around (6.5, 6.5), spread 1.6), depth-3 trees, and the test point (5, 5) halfway between the blobs. Over 2000 seeded replications (mulberry32) we record each tree's 0-or-1 vote at (5, 5) and measure sigma squared and rho; estimates are rounded to 2 decimals before plugging in.
Step 1 — measure one tree, then a bagged pair
A lone tree's vote at (5, 5) flips between 0 and 1 from sample to sample, so its variance sits at the maximum 0.25. Bagged trees may use both features at every split, and their votes correlate at 0.31.
Step 2 — variance of a 3-tree bagged average
Averaging already halves the single-tree variance of 0.25 — but notice the 0.0775 term does not shrink with B.
Step 3 — feature subsampling decorrelates the trees
Forest trees see only 1 of the 2 features at each split, so trees grown on the same data disagree more: sigma squared stayed at 0.25 while rho fell from 0.31 to 0.22.
Step 4 — the floor that more trees cannot break
Adding trees kills the second term only. The correlated part survives forever, so the only way to lower the floor is to lower rho — exactly what feature subsampling does.
Step 5 — the same story in three actual votes
One seeded run (dataset seed 10007, ensemble seed 42): the bagged trio moves in lockstep, so averaging clones buys little; the forest trio disagrees at (5, 5) — that visible diversity is what the smaller rho was measuring.
What just happened: With sigma squared pinned at 0.25, cutting the tree correlation from 0.31 to 0.22 lowered the 3-tree variance from 0.135 to 0.12 and the infinite-tree floor from 0.0775 to 0.055 — feature subsampling, not more trees, is what moved the floor.
Now Break It
Try this: Using all features per split makes every tree nearly identical, defeating the ensemble.
Control: Features-per-split slider (set to all)
What happens: Trees too correlated! Using every feature per split makes all trees alike — no diversity gain.
Where random forest is used
Random forests are a workhorse for tabular data across industry. Banks use them for default and churn prediction, insurers for claim triage, and biologists for gene-expression classification, partly because they handle mixed numeric and categorical features with minimal preprocessing and no scaling. Their built-in feature-importance scores make them a popular first pass for understanding which variables matter before a more tuned model is built. In fraud and recommendation pipelines they serve as strong baselines and as feature generators. Because trees train independently, a random forest scales across cores easily, and the out-of-bag error gives a quick internal estimate of accuracy. They are often the default answer when someone wants a good tabular model with little tuning effort.
A common misconception is that random forests cannot overfit. They can: with very deep trees on small or noisy datasets they will memorize, and adding more trees does not fix that, it only stabilizes the averaged prediction. More trees never hurt accuracy but do cost time and memory, so the number of trees is a compute knob, not a regularizer. The real regularization comes from tree depth, minimum leaf size, and the number of features sampled per split. Another pitfall is trusting the default impurity-based feature importances, which are biased toward high-cardinality and continuous features; permutation importance on held-out data is more reliable. Finally, forests extrapolate poorly, predicting flat values outside the range of the training targets.
Frequently asked questions
What is a random forest?
How is a random forest different from plain bagging of trees?
Do more trees cause a random forest to overfit?
How does a random forest measure feature importance?
When should I choose a random forest?
Written & reviewed by the ML Visualization team · Last updated .