Sub topic 1
Why Combine Models at All?
Prerequisites
Assume you know supervised learning, train/validation/test splits, and basic scikit-learn use. You should also understand overfitting and cross-validation.
Why Combine Models at All
A single model has a particular view of the data. A linear model captures broad trends. A decision tree captures rules and interactions. A nearest-neighbor model uses local similarity. Each model makes different mistakes.
An ensemble combines several models. In stacking, a second model, called the meta-learner, learns how to use the first models' predictions. The first models are called base learners.
A combination can outperform every individual model when its errors are not identical. If one model misses an example but another recognizes it, the ensemble can learn when to prefer each model.
Why Diversity Matters More Than Count
Adding more models does not automatically improve an ensemble. Ten nearly identical random forests may make nearly identical errors. Their extra predictions add little information.
Diversity means that models use different assumptions, features, algorithms, or training samples. Useful diversity comes from models that are individually reasonable but fail in different places.
A small group of diverse models is often better than a large group of similar models. Compare validation performance and error patterns instead of counting models.
>``callout note > Diversity does not mean keeping a weak model just because it is different. A base learner should provide useful information that the others do not already provide. >``
Choosing Base Learners
Choose models with complementary strengths. A practical starting group might include:
- A regularized linear model for smooth, additive relationships.
- A tree ensemble for nonlinear rules and feature interactions.
- A scaled nearest-neighbor model for local patterns.
Use pipelines when preprocessing differs between models. Keep the group small until validation shows that another model adds value.
The Meta-Learner: A Model That Learns from Models
The meta-learner receives the base learners' predictions as input features. It can learn patterns such as “trust the tree model more when the linear model is uncertain.”
For classification, these inputs are called meta-features. The meta-learner is often a simple, regularized logistic regression because a complex second model can overfit the limited prediction features.
Meta-Features: Probabilities or Labels
A base learner can provide either a hard label, such as spam, or class probabilities, such as 0.82 spam and 0.18 not spam. Probabilities usually preserve more information about confidence. Labels are simpler and can work when probabilities are poorly calibrated.
Train the meta-learner only on predictions produced without training on the same rows. This prevents it from learning unrealistically optimistic patterns.
Exercise
Why might three diverse models beat ten similar models?
Show answer
Diverse models are more likely to make different errors, giving the meta-learner useful information to combine.