Ensemble Methods: Random Forests, Bagging, and Gradient Boosting
Decision Trees closed with a warning: one tree is unstable. This page is the fix — stop trusting any single tree, and combine many.
Intermediate
| Step | What happens |
|---|---|
| 1 | draw a bootstrap sample: randomly sample m rows from the m-row training set, with replacement, so some rows appear multiple times and others not at all |
| 2 | train one full decision tree on that bootstrap sample |
| 3 | repeat steps 1-2 independently, B times, building B different trees on B different bootstrap samples |
| 4 | to predict a new CI run: average the B trees' predictions (regression), or take a majority vote (classification) |
1/B — the
individual mistakes cancel rather than compound. Because every tree trains on its own
bootstrap sample with no dependency on any other tree, all B trees can be trained in
parallel — a practical advantage bagging has over the sequential approach below.
touches_slow_suite
from Decision Trees' entropy example — is a genuinely
dominant predictor, nearly every bootstrap sample will still pick it as the best root split,
because it's the best split for almost any subset of the data. The trees end up correlated
with each other despite training on different data, which weakens the variance-cancellation
argument above — correlated errors don't average away as well as independent ones do.
touches_slow_suite at a given split has to find the next-best available feature
instead, producing meaningfully different trees even when they're trained on similar
bootstrap samples. This one change — feature subsampling at each split, on top of bagging's
row subsampling — is the entire difference between "bagged trees" and a "random forest."
| Step | What happens |
|---|---|
| 1 | start with a naive first model — even something as crude as always predicting the average CI duration |
| 2 | use the current ensemble to predict every training example, and compute the loss (e.g. MSE from Linear Regression) |
| 3 | fit a new tree whose job is specifically to reduce that loss — in practice, to predict the current ensemble's errors (residuals) |
| 4 | add the new tree to the ensemble, scaled down by a small learning rate so no single tree dominates |
| 5 | repeat from step 2, with the ensemble now including the new tree |
| Bagging / Random Forest | Boosting (Gradient Boosting / XGBoost) | |
|---|---|---|
| Trees built | independently, in parallel | sequentially, each depending on the last |
| Primarily fixes | variance (instability) — individual deep trees can stay complex | bias — individual trees are often deliberately shallow ("weak learners") |
| Overfitting behavior | adding more trees rarely hurts; variance keeps shrinking | adding too many rounds, or trees too deep, can genuinely overfit — needs the regularization and early-stopping ideas from earlier in this track |
| Training cost | parallelizable across trees | inherently sequential, though each tree is often shallower and cheaper |
| Typical accuracy ceiling | strong, reliable default | often the higher ceiling on tabular data, at the cost of more careful tuning |