Stacked Generalization

Machine Learning
Introduced by
David Wolpert
Year
1992
Type
meta-learning aggregation
Family
Ensemble

What does it do?

Stacked generalization, or stacking, is a two-level ensemble method in which base-level models are trained on the original data and a meta-learner is trained on the predictions of those base models.

Rather than applying a fixed aggregation rule such as voting or averaging, the meta-learner learns how to combine the base predictions. David Wolpert introduced the approach in 1992.

The intuition behind the method

Simple voting treats all base models alike, even though they often differ in accuracy and in the kinds of errors they make. Stacking replaces the fixed rule with a second-level model that learns how much weight to give each base model, and in which situations. Its input is the set of base predictions, so the meta-learner can pick up patterns such as one model being reliable on one region of the input space and another on a different region. In that sense it resembles a decision-maker who has learned which expert to trust for which kind of case.

History

David Wolpert formalised stacked generalization in 1992 in Neural Networks, describing a meta-level generalizer trained on the guesses of base generalizers.

When to use it

Choose stacking when you have several base models that are reasonably accurate on their own and make different kinds of errors, for example tree-based models alongside linear or kernel models. It suits problems where a simple average or vote is clearly leaving accuracy on the table and where there is enough data to hold out out-of-fold predictions for training the meta-learner. Avoid it when the base models are highly correlated, since the meta-learner then has little new information to combine. It is also a poor choice when the dataset is small, because the out-of-fold predictions become noisy, or when a single transparent model is required, because the final prediction is hard to explain.

Limitations and considerations

  • The meta-learner can overfit the out-of-fold predictions if it is too flexible or if the validation procedure is not kept separate from the final evaluation.
  • Cost grows with the number of base models and with the number of folds used to build the meta-features, since each base model must be trained once per fold plus once more on the full data.
  • The best meta-learner depends on the problem and on the number of base models, and no single choice works universally.
  • The final prediction is a composition of several models, so the reasoning behind it is harder to explain than that of any single base model.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Learns the combination weights from data, so it can give different weight to base models that are reliable in different regions of the input space instead of applying one fixed rule.
  • Can exploit complementary errors of heterogeneous learners, such as trees and linear models, because the meta-learner sees each model's predictions as separate features.
  • Uses the out-of-fold scheme to train the meta-learner on predictions that were not produced on the data each base model was trained on, which keeps the meta-training signal honest.

Applications

  • Tabular prediction tasks in which gradient-boosted trees, linear models and kernel support vector machines are combined, with a simple meta-learner weighting each model's output.
  • Credit risk assessment, where several credit risk models are combined through a stacked generalization approach, with the meta-level model integrating their outputs into a final assessment (Doumpos and Zopounidis, 2007).
  • Classification problems in which base classifiers return class probabilities, and the meta-learner recalibrates and combines these probability scores into a final decision.

How it works

How it works

1

Train K base models (level-0 models) on the original training data. They should differ in algorithm, hyperparameters or training sample so that their errors are not identical.

2

Build the meta-training data out of sample. Split the training data into folds (k-fold cross-validation), train each base model on all folds except one, and record its predictions on the held-out fold. Repeating this over all folds gives every training row a prediction from base models that never saw that row. The K prediction columns, paired with the true targets, form the meta-training dataset.

3

Train a meta-learner (level-1 model, often a simple model such as logistic regression) on the meta-training dataset, so that it learns how to combine the base predictions.

4

For a new sample, pass it through each base model to obtain K predictions, use these as the meta-features, and pass them through the trained meta-learner to produce the final prediction. The base models used here are normally refitted on the full training data.

Common pitfalls

  • Training the meta-learner on predictions made for rows the base models were fitted on. This leaks information and inflates apparent accuracy; out-of-fold predictions or a separate hold-out set avoids it.
  • Choosing a meta-learner that is too complex for the number of meta-features, for example a large random forest fitted to only a few base predictions.
  • Assuming diversity without checking it. Base models that make the same errors give the meta-learner little to combine, so the stacked result may barely beat its strongest member.
  • Tuning the meta-learner's hyperparameters on the same meta-features used to report performance, which makes the reported score optimistic. Keep a separate test set that plays no part in generating meta-features or tuning the meta-learner; tune the meta-learner by cross-validation on the meta-features and report results only on that test set.

Frequently asked questions

How do I avoid overfitting in stacking?

Use k-fold cross-validation to generate meta-features: each fold's held-out predictions become meta-training data, so the meta-learner never sees predictions made on data used to train the base models. Keep a separate test set, untouched by meta-feature generation and meta-learner tuning, for the final evaluation.

What model should I use as the meta-learner?

Simple models often work best: logistic regression, linear regression, or a small decision tree. Complex meta-learners (random forests, neural networks) risk overfitting to the meta-features. Start simple and only add complexity if validation performance plateaus.

Should base classifiers be trained on the same data?

Not necessarily. Diversity in algorithm, hyperparameters, or training sample can improve meta-learner generalization, for example when base classifiers are trained on different bootstrap samples (as in bagging) or with different algorithms. Identical base classifiers produce identical predictions and give the meta-learner nothing new to combine. Diversity should be checked rather than assumed, for instance by measuring the correlation of errors between base models.

Can I use stacking with regression and classification?

Yes. For regression, the meta-learner predicts continuous values from base regressor outputs. For classification, it predicts classes from base classifier probability scores. The principle is identical.

Related methods

Sources

  1. Wolpert, D. H. (1992). Stacked generalization. Neural Networks, 5(2), 241-259.

    Open DOI reference
  2. Breiman, L. (1996). Stacked regressions. Machine Learning, 24(1), 49-64.

    Open DOI reference
  3. SPC, p. 15