advancedadvanced-ml

Stacking & Blending

Train a model whose only job is to learn how to best combine your other models.

Key Points

What it is

Stacking (and its simpler cousin, blending) is an ensemble technique where predictions from several different base models are used as input features to train a final 'meta-model,' which learns the best way to combine them into one final prediction.

Why it exists

Different model types make different kinds of mistakes — a tree-based model and a linear model fail on different examples. Stacking exists to let a learned meta-model exploit those different failure patterns, rather than combining models with a fixed rule like simple averaging or majority voting.

Intuition

Imagine a panel of three expert consultants, each with a different specialty, giving their opinion on a business decision. Instead of just averaging their opinions equally, you hire a fourth expert whose entire job is to learn, over time, which consultant to trust more in which situations — that fourth expert is the meta-model.

How it works

  1. Train base models

    Train several different models (e.g. Random Forest, SVM, k-NN) on the training data using cross-validation to avoid leakage.

  2. Generate meta-features

    Use each base model's out-of-fold predictions as new input features for the meta-model.

  3. Train the meta-model

    Fit a typically simple model (e.g. logistic regression) on these meta-features to produce the final prediction.

  4. Predict on new data

    At inference time, run new data through all base models first, then feed their outputs into the trained meta-model.

When to use

When not to use

Common mistakes

In practice

A common technique in Kaggle-style machine learning competitions and select high-value production systems, though rarely used in early-stage or resource-constrained projects due to its added complexity.

Was this concept helpful?

Spot an error or gap? Suggest an edit →

Related concepts

ensemble-methodsgradient-boostingrandom-forest
Chirp at me!