TL;DR
Model selection means choosing which of several candidate models to use. You usually have a family of options, such as polynomials of different degrees or regressions with different sets of inputs, and you want the one that predicts new data best. A more complex model always fits the data you already have at least as well, so fit alone cannot decide. You need a score that estimates performance on unseen data, either from held-out examples or from a penalty that charges each extra parameter a price.
Where you'll see it: choosing the degree of a polynomial, choosing which predictors go into a regression, choosing the number of clusters or topics, and choosing the depth of a decision tree or the strength of a regularisation penalty.
Intuition
The flexibility trap
Suppose you have twelve points scattered around a gentle curve and you try to fit them with a polynomial. A straight line misses the bend. A cubic follows it. A degree-11 polynomial passes through all twelve points exactly, with zero error on the data it saw. Yet if you draw a new point from the same process, the wiggly degree-11 curve is likely to miss it badly, because it learned the noise in those twelve points along with the shape.
This is Overfitting, and it is the reason model selection exists. The training error keeps falling as complexity rises, but the error on new data falls and then rises again. The model that is best for the future sits somewhere in the middle, which is the Bias-Variance Tradeoff seen from the model-choice side.
- training error
- error on new data
Two ways to estimate the future
There are two families of answers to "how well will this model do on new data?"
- Measure it directly. Keep some data out of the fitting. Fit each candidate on the rest, score it on the held-out part, and pick the winner. This is the validation set from Train, Validation and Test Sets, and cross-validation is the same idea repeated over several splits.
- Correct the training score. Use the likelihood the model achieves on the training data, which is always too optimistic, and subtract a penalty for the number of parameters. Akaike's information criterion (AIC) and the Bayesian information criterion (BIC) do this. Mallows' C_p does it for least-squares regression.
Both aim at the same target. Held-out scoring is simpler to trust and works with any model. Penalised scores need no extra data and are cheap to compute, but they rely on assumptions about the model being roughly right.
The math
Let the data be with observations. Candidate model has free parameters , and we fit it by Maximum Likelihood Estimation. Write for its log-likelihood on the training data and for the maximiser, so is the best training log-likelihood the model reaches.
For a new observation drawn from the same process, the quantity we want to minimise is . Smaller means the fitted model assigns higher probability to data it has not seen.
The training log-likelihood estimates the opposite of this quantity and is biased in the model's favour, because was chosen to fit exactly these observations. Model selection is about removing that bias.
AIC
Lower is better. The first term is a penalty of 2 per parameter. The second term rewards fit.
Akaike (1974) showed that, for a model close to the truth and a large sample, the gap between the training log-likelihood and the expected out-of-sample log-likelihood is about on average. The derivation is in his paper; the shape of the argument is:
- On new data, the expected log-likelihood is about .
- Multiply by : the expected out-of-sample deviance is about .
- That is , up to a constant that is the same for every candidate.
So AIC is an approximately unbiased estimate of out-of-sample deviance, with one parameter costing about two units.
BIC
Lower is better. The penalty per parameter is , so it grows with the sample size.
BIC comes from a different starting point. Schwarz (1978) approximated the marginal likelihood of each model (the probability of the data averaged over the parameter prior) and found that times its logarithm is, to leading order, the BIC above. Choosing the lowest BIC therefore picks the model with the highest approximate posterior probability when all candidates start equally likely.
The two penalties differ only in how they scale: AIC charges 2 per parameter, BIC charges . Once exceeds about , BIC is the harsher of the two. In practice BIC tends to choose smaller models, and AIC tends to choose models that predict slightly better.
Mallows' C_p for least squares
For linear regression with residual sum of squares from a submodel with coefficients (intercept included), and an estimate of the noise variance taken from the full model with coefficients:
If the submodel has no bias, is about on average. A well above means the submodel leaves out something real. This is the regression-specific cousin of AIC; see Mallows Cp.
- List the candidate models and fit each one by maximum likelihood on the training data.
- For each, compute the score: a held-out error, or AIC, or BIC, or .
- Choose the candidate with the lowest score. Ties and near-ties are a signal that several models are equally good.
- Refit the chosen model on all the data before using it, if you held data back to score it.
- Report the score on a test set that played no part in the choice. The selection step makes the selected model's own score look better than it will be on the future.
Worked examples
We observe 10 flips with 7 heads. Two candidates:
- : a fair coin with fixed. It has free parameters.
- : a coin with an unknown bias . Its MLE is , so .
- Log-likelihood of : .
- Log-likelihood of at : .
- . .
- . .
- Both criteria pick .
Interpretation: the bias estimate improves the log-likelihood by only , which is less than the unit that one extra parameter costs on the log scale. The data are consistent with a fair coin, and the extra parameter does not earn its place. With 100 flips and 70 heads the improvement would be far larger and would win.
A team fits polynomial regressions of degree 1 to 5 to a sensor calibration curve. They split the data into a training set and a validation set, fit each model on the training set, and record the mean squared error on the validation set (illustrative numbers):
| Degree | Validation MSE |
|---|---|
| 1 | 4.2 |
| 2 | 2.1 |
| 3 | 1.6 |
| 4 | 1.9 |
| 5 | 2.8 |
- The smallest validation error is 1.6, at degree 3.
- Degrees 4 and 5 fit the training points more closely, yet their validation error rises. That rise is overfitting, visible in data the model did not train on.
- Degree 1 is too rigid: its error is more than double the best.
- The team refits degree 3 on training plus validation data, then reports error on a separate test set that was never used for choosing. Say that test error is 1.7. That number, not 1.6, is the honest estimate of performance on new readings.
Interpretation: the validation score did its job, but it was optimised over five candidates, so it is slightly optimistic. The separate test set guards against that.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Very little data | A held-out split wastes samples and the score is noisy | Cross-validation or AIC/BIC |
| Large data, prediction is the goal | BIC can pick too small a model | AIC, or held-out error on a test set |
| Goal is to find the true structure | AIC keeps extra terms that do not matter | BIC, which is more consistent when the truth is in the candidate set |
| Models are far from the truth | AIC and BIC approximations break down | Held-out scoring, which makes no such assumption |
| Many candidates compared | The winner's score is optimistic (selection bias) | Keep a final test set that is never used for choosing |
| Penalised models with a continuous knob | A grid of models is coarse and slow | Regularisation strength tuned by validation, as in L2 Regularization or Lasso Regression |
A common mistake is to select on the test set and then report its error as the final performance. Each time you look at it to choose, it stops being a test set.
History
Mallows introduced in the early 1970s as a practical tool for choosing subsets of regression variables, reading it off the residual sums of squares of candidate subsets. Stone (1974) studied cross-validation as a way to choose and assess predictive models. Akaike published AIC in 1974, framing model choice as estimating the information lost when a fitted model replaces the true process. Schwarz (1978) derived BIC from a Bayesian argument about posterior model probabilities. The two criteria are still the standard pair, and most statistics software reports both.
Model selection caught on because it turned a qualitative worry, that complex models overfit, into a number that could be compared. The debate over which criterion to use has continued since, and it is a debate about what you want the model for: prediction or identification.
Check yourself
QuestionRecall: why can't the training log-likelihood alone decide between a degree-3 and a degree-8 polynomial?Show answer
A higher-degree polynomial can always match the training data at least as well, because it contains the lower-degree ones as special cases. So the training likelihood never penalises extra flexibility, and the simpler model cannot win on fit alone. A criterion that estimates out-of-sample performance must add a cost for complexity, either by holding out data or by penalising parameters.
QuestionComputation: model X has and maximised log-likelihood . Model Y has and maximised log-likelihood . Compute AIC for each, and say which AIC prefers. Then compute BIC for .Show answer
AIC for X: . AIC for Y: . AIC prefers X by 2 units.
For BIC with , . BIC for X: . BIC for Y: . BIC prefers Y.
The two criteria disagree here because the two extra parameters in X buy 6 units of deviance (). AIC charges for them, a net gain of 2 for X. BIC charges about , which is more than 6, so Y wins.
QuestionWhy: BIC's penalty per parameter grows with , while AIC's stays at 2. What does that imply for very large datasets?Show answer
As grows, grows without bound, so BIC keeps adding a larger penalty for every parameter. With enough data, BIC will reject a real but small effect that AIC would keep, because AIC's penalty does not rise with the amount of evidence. The implication is that BIC favours parsimony more strongly at large , which suits identifying a true structure but can hurt prediction when many small effects matter.
QuestionApplied: a team compares 20 candidate regressions for predicting daily energy use from 3,000 days of data. They pick the best by AIC on the full dataset, then report that AIC-chosen model's training error as its performance. What is wrong, and what should they do?Show answer
Two things. First, the training error is optimistic: it is the error on the data used to fit and to choose, so it understates the error on future days. Second, AIC is an approximation that assumes a model close to the truth, so the penalty may be imperfect. They should hold out a test period (for example the last 365 days), select using only the earlier data by AIC or validation error, and report the error on the untouched test period. Comparing the chosen model's test error with the others' gives an honest check on whether the selection helped.
QuestionRecall: what is a validation set, and how does it differ from a test set?Show answer
A validation set is data held out from fitting and used to compare candidate models or tune their settings. A test set is data held out from both fitting and choosing, used once to report the final performance. Reusing the validation set to report performance makes the reported number optimistic, which is why the two roles are kept apart.