What is stacking in ensemble learning?
Ensemble learning combines the predictions of several models to get a result that is more accurate and more stable than any one of them. The simplest combiners are voting rules: hard voting takes the majority class, and soft voting averages predicted probabilities. Stacking, or stacked generalization, goes further and trains a second-level model, the meta-learner, to decide how to combine the base models' predictions.
Ensembles work because different models make different mistakes, and combining them cancels some of those errors. Stacked ensembles of gradient-boosted trees, neural networks, and linear models are a common recipe in machine learning competitions, and AutoML systems such as AutoGluon and H2O build stacked ensembles automatically. The cost is extra training time and a model that is harder to explain and to deploy.
Key ideas
- An ensemble combines several models so that their individual errors partly cancel.
- Ensembles gain the most when the base models are accurate and make different mistakes.
- Hard voting counts predicted labels, while soft voting averages predicted probabilities.
- Stacking trains a meta-learner on the base models' out-of-fold predictions.
- Out-of-fold predictions keep the meta-learner from trusting overfit base models.
- A simple, regularized meta-learner such as logistic regression is usually enough.
Common questions
What is the difference between stacking and blending?
Blending is a simpler version of stacking. Instead of out-of-fold predictions from cross-validation, it holds out a single validation set, trains the base models on the rest, and fits the meta-learner on their predictions for the holdout. It is faster and easier to implement, but the meta-learner learns from less data.
How is stacking different from bagging and boosting?
Bagging and boosting usually combine many models of the same type, trained on resampled data or on the errors of earlier models. Stacking combines different model types and learns the combination from data. The approaches mix well: a stacked ensemble often uses a random forest and a boosted model as two of its base learners.
Which models make good base learners for stacking?
Models that are each reasonably accurate but work in different ways, for example gradient-boosted trees, k-nearest neighbors, a neural network, and a regularized linear model. Diversity matters more than adding another strong model of the same kind, because similar models make the same mistakes.
Does stacking always improve accuracy?
No. If the base models are highly correlated, or the dataset is small, a stacked ensemble may do no better than the best single model or a simple average. It also multiplies training and inference cost, so the gain has to justify the added complexity.
Related explainers
- Bagging & Random Forests — Bootstrap aggregation and decorrelated tree ensembles
- Gradient Boosting — Sequential residual fitting for powerful predictions
- Cross-Validation — K-fold, stratified, and leave-one-out evaluation
- Decision Trees & Splitting — Recursive partitioning, Gini impurity, and pruning
- Model Evaluation & Metrics — Precision, recall, F1, ROC curves, and regression metrics
- Overfitting & Underfitting — The bias-variance tradeoff and generalization
References
- Wolpert (1992), "Stacked Generalization", Neural Networks
- Breiman (1996), "Stacked Regressions", Machine Learning
- Dietterich (2000), "Ensemble Methods in Machine Learning", Multiple Classifier Systems
Last updated