Lesson 3.9core3 h 30 min

Ensembles: bagging, random forests and gradient boosting

Many weak opinions, combined carefully, beat one strong one

Gradient-boosted trees are the default winner on tabular data in 2026 and random forests are the most forgiving model you can reach for. The math here — variance of an average of correlated predictors, boosting as gradient descent in function space — reappears in deep-learning optimizers (4.5 Optimizers and learning-rate schedules), in self-consistency voting for LLM outputs (8.5 Decoding and sampling) and in agent voting/ensembling patterns (10.5 Agentic workflow patterns).

You'll be able to

  • Derive the variance of an average of B correlated predictors and explain why decorrelation is the goal of bagging and random forests
  • Explain gradient boosting as functional gradient descent and show that fitting residuals is the squared-loss special case
  • Describe what XGBoost, LightGBM and CatBoost each added to plain gradient boosting
  • Choose and tune a GBDT sensibly and know when tree ensembles beat deep learning

Key ideas

  1. Var(average of B models) = ρσ² + (1−ρ)σ²/B: averaging removes the independent part of the variance, correlation ρ sets the floor.
  2. Bagging trains on bootstrap samples (≈63.2% unique rows; the rest are out-of-bag and give free validation); random forests also sample features per split to decorrelate trees.
  3. Forests use deep trees and reduce variance; boosting uses shallow trees added sequentially and reduces bias.
Show 4 more key ideas
  1. Gradient boosting = gradient descent in function space: fit each new tree to pseudo-residuals −∂L/∂F; for squared loss these are plain residuals.
  2. XGBoost scores trees with a second-order expansion: leaf weight −G/(H+λ) and an explicit split gain; LightGBM adds histogram/leaf-wise speed; CatBoost adds ordered target statistics.
  3. Tune learning rate + early-stopped number of trees first, then depth/leaves, min child weight, subsampling and regularization.
  4. GBDTs still beat deep learning on typical tabular data; deep learning wins on perceptual data and with transfer learning.

Suggested path through this lesson