🟣 Technical 10 min read

Ensemble Methods Explained: Bagging, Boosting, and Random Forests

Ensemble methods combine multiple models to produce better predictions than any single model. Here's how bagging, boosting, and random forests actually work.

View all machine learning depths →

There’s a reliable principle in machine learning: a committee of mediocre models usually beats one brilliant model. This is the core insight behind ensemble methods — and it shows up in competition-winning solutions, production ML systems, and some of the most robust algorithms in the field.

Why ensembles work

To understand ensembles, you need to understand the bias-variance tradeoff. Every model makes two kinds of errors:

  • Bias: Systematic errors from wrong assumptions. A linear model trying to fit a curved dataset has high bias — it’s consistently wrong in the same direction.
  • Variance: Sensitivity to small changes in the training data. A very deep decision tree might fit the training set perfectly but wildly overfit to noise.

Different models fail in different ways. If you combine models that fail independently, their errors tend to cancel out. A prediction that’s correct in 70% of models will beat a single model that’s randomly right or wrong.

This only works if the models make diverse errors. Ensembling three identical models gives you nothing. Ensembling three models trained differently — on different data subsets, with different hyperparameters, or using different algorithms — can be powerful.

Bagging: variance reduction through sampling

Bagging (Bootstrap AGGregating) is the simplest ensemble strategy. The idea:

  1. From your training dataset of N examples, create B bootstrap samples — each is a random sample of N examples drawn with replacement. This means some examples appear multiple times; some don’t appear at all.
  2. Train a separate model on each bootstrap sample.
  3. At prediction time, average the predictions (for regression) or take a majority vote (for classification).

Why does this help? Because each model sees a slightly different training set, it makes different errors. Averaging across them reduces variance without meaningfully increasing bias.

Bagging works best with high-variance, low-bias base models — like fully-grown decision trees. A single deep decision tree overfits badly; bagging many of them smooths out the noise.

Random Forests: bagging with extra randomness

Random Forests are the most famous bagging variant. They add one crucial modification on top of bagging:

At each split in each tree, only consider a random subset of features (typically √p features for p total features).

Why? Because without this, all your trees will tend to look similar — they’ll all use the strongest features at the top, leading to correlated errors. The random feature selection forces trees to find diverse solutions, producing genuinely different trees that fail differently.

The result is remarkably robust:

  • Handles missing data reasonably well
  • Naturally provides feature importance scores (features used more at the top of trees matter more)
  • Parallelizes easily (each tree is independent)
  • Rarely catastrophically wrong — the averaging makes outlier predictions rare

Random Forests remain one of the most reliable go-to algorithms for tabular data. Even in 2026, many production ML systems use Random Forests for parts of their pipeline because they’re interpretable, fast to train, and hard to break.

Boosting: bias reduction through sequential learning

Boosting takes the opposite approach. Instead of training models in parallel on random samples, it trains models sequentially — each one explicitly trying to fix what the previous models got wrong.

The general algorithm:

  1. Train a simple base model (often a “weak learner” — a model only slightly better than random).
  2. Look at the training examples it got wrong or predicted with high error.
  3. Train the next model with more emphasis on those hard examples.
  4. Repeat. Combine all models with learned weights.

This process reduces bias — each round, the ensemble gets better at the hard cases. The risk is overfitting if you run too many rounds on noisy data.

AdaBoost: the original

AdaBoost (Adaptive Boosting) implements this directly: each misclassified example gets higher weight in the next training round. Models that perform well get higher weight in the final vote.

AdaBoost was revolutionary when introduced in 1997 and is still used today, though it’s been largely superseded by gradient boosting.

Gradient Boosting: the modern standard

Gradient Boosting reframes boosting as a gradient descent problem. Instead of reweighting examples, each new tree is trained to predict the residual errors (more precisely, the negative gradient of the loss function) of the current ensemble.

At each step you add a small tree that “fills in” what the current model is getting wrong. With a low learning rate and many rounds, this process can squeeze extraordinary performance out of tabular data.

XGBoost, LightGBM, and CatBoost are the dominant gradient boosting libraries. They add:

  • Regularization to prevent overfitting
  • Efficient handling of sparse data
  • Built-in cross-validation
  • GPU acceleration
  • Native categorical feature handling (CatBoost)

Gradient boosting consistently wins tabular data competitions (Kaggle, etc.) and is widely used in production for structured data: credit scoring, fraud detection, recommendation ranking, ad click prediction.

Stacking: ensembling the ensembles

Stacking goes a level further. Instead of averaging predictions, you train a meta-model to combine the outputs of multiple base models.

The setup:

  1. Train several diverse base models (could be anything: Random Forest, XGBoost, SVM, neural network, linear regression)
  2. Use cross-validation to generate out-of-fold predictions from each base model
  3. Use those predictions as features to train a meta-model (often a simple logistic regression or a linear model)
  4. At test time, each base model predicts; the meta-model combines those predictions into the final output

Stacking can extract value from genuinely different model types. A Random Forest and a neural network fail in completely different ways — a meta-model can learn to trust each in different regions of the feature space.

The cost: significant complexity, longer training pipelines, and much harder to explain to stakeholders.

Practical guidance

For tabular data:

  • Start with Random Forests for quick baselines — they’re fast, robust, and need minimal tuning
  • Move to gradient boosting (LightGBM is usually fastest) when you need to squeeze more performance
  • Use stacking only if you’re in a competition or the performance gain justifies the complexity

For time series:

  • Gradient boosting with time-aware features often wins
  • Be careful with bagging — random sampling can break temporal structure

Hyperparameters that matter most:

  • For Random Forests: n_estimators, max_features, max_depth
  • For gradient boosting: learning_rate, n_estimators, max_depth, subsample

The key interaction: learning rate and n_estimators trade off — a lower learning rate needs more trees to converge, but usually generalizes better. A common approach: set a small learning rate (0.01–0.05) and use early stopping to find the right number of trees.

When not to use ensembles

  • When you need interpretability. A single decision tree is explainable; 500 trees are not.
  • When inference speed is critical and you can’t afford the compute.
  • When you have very little data — the variance benefits of bagging require enough data for diverse training subsets to be meaningful.
  • When you’re working with image, text, or audio at scale — deep learning dominates there, and the ensemble logic gets baked into the architecture differently.

The bottom line

Ensemble methods are one of the most reliable tools in the ML practitioner’s toolkit. Random Forests for quick, robust baselines. Gradient boosting for performance on structured data. Stacking when you have the time and infrastructure to make it worthwhile.

If you’re working on a tabular prediction problem and haven’t tried gradient boosting, that’s your next step.

Simplify

← Model Calibration: When Your Model Says 90% Confident, Is It Right 90% of the Time?

Go deeper

Machine Learning Explainability: SHAP, LIME, and Beyond →

Related reads

machine-learningensemblerandom-forestgradient-boostingbaggingboosting

Stay ahead of the AI curve

Weekly insights on AI — explained at the level that's right for you. No hype, no jargon, just what matters.

No spam. Unsubscribe anytime. We respect your inbox.