Ensemble Methods
Better Together — Bagging, Boosting, and Stacking
Ensemble methods combine multiple models to produce predictions more accurate than any single model alone. Diversity between models is the key to their power.
- Bagging — trains models independently on different data samples and averages their predictions to reduce variance
- Boosting — trains models sequentially, with each correcting the errors of the previous ensemble
- Stacking — combines different model types with a meta-learner that learns the optimal way to blend predictions
"If you want to go fast, go alone. If you want to go far, go together."
Ensemble Methods — Complete Guide
Ensemble methods combine multiple models to produce better predictions than any single model.
Types of Ensembles
Ensemble Architecture Comparison
Bagging (Bootstrap Aggregating):
Train models INDEPENDENTLY on different data samples
Combine by averaging/voting
Reduces variance
Example: Random Forest
Boosting:
Train models SEQUENTIALLY
Each model corrects previous errors
Reduces bias and variance
Example: XGBoost, AdaBoost
Stacking:
Train different model types
Train a meta-learner to combine predictions
Uses diverse base models
Often wins competitions
Voting:
Hard voting: majority wins
Soft voting: average probabilities
Simple but effective
Mathematical Foundation
Ensemble Error Decomposition
For an ensemble of
models with individual error
and pairwise correlation
:
where
is the average correlation between model errors.
Key insight: Diversity (
) is what makes ensembles work. The more uncorrelated the errors, the more the ensemble reduces variance.
Boosting as Gradient Descent
Boosting can be viewed as gradient descent in function space:
where
is the learning rate and
fits the negative gradient:
Python Implementation
Ensemble Error Analysis
When to Use Each Method
Key Takeaways
What to Learn Next
-> Random Forest Dive deep into bagging with Random Forest — the most popular ensemble method.
-> XGBoost Master gradient boosting, the sequential ensemble technique that dominates Kaggle competitions.
-> Decision Trees Understand the base learners that ensemble methods combine for stronger predictions.
-> Model Evaluation Evaluate ensemble performance with cross-validation and understand when ensembles help.
-> Interpretability Use SHAP values to explain black-box ensemble model predictions.
-> AutoML Automate model selection and ensemble construction with automated machine learning.