TL;DR
The Akaike information criterion (AIC) scores a fitted model by how well it fits the data, with a penalty of 2 for each parameter the model uses. You fit every candidate by Maximum Likelihood Estimation, compute its AIC, and prefer the lowest value. The score estimates how well the model will predict new data, which is what Model Selection needs and what training fit alone cannot supply.
Builds on: Kullback–Leibler Divergence, Maximum Likelihood Estimation, Model Selection · Leads to: Bayesian Information Criterion (BIC), Mallows Cp
Where it's used
Choosing the order of a forecasting model. A company forecasting weekly demand fits several autoregressive time-series models that differ in how many past values they use. Software such as R's auto.arima searches over such candidates and, by default, uses a small-sample corrected version of AIC to pick the one that does the forecasting.
Choosing how to model DNA change. Biologists who build evolutionary trees from DNA sequences must assume a model of how often each base changes into each other base. Phylogenetic programs fit many such models to the same alignment and rank them with AIC or BIC, so the tree is inferred under a model the data support.
Comparing regressions in everyday analysis. An analyst deciding which predictors belong in a Linear Regression of house prices fits several versions and reads each one's AIC from the software output. All the versions are fitted to the same houses, so their scores can be compared directly.
How it works
Take the smallest case that shows the mechanism. Flip a coin 4 times and see 3 heads. Two candidates compete:
- A: a fair coin, with the heads probability fixed at 0.5. It has no free parameters.
- B: a coin with an unknown heads probability . Its maximum likelihood estimate is , so it has one free parameter.
- Score A by the probability it gives the data. Each flip has probability 1/2, so the four flips together have probability . Its log-likelihood is . Check: , which is .
- Score B at its best value. With , one particular sequence, heads, heads, heads, tails, has probability . Its log-likelihood is . Check: B fits this data better than A, because it chose to suit the data.
- Measure the gain from the extra parameter: . One extra parameter improved the log-likelihood by only about half a unit.
- Charge the penalty. AIC multiplies the log-likelihood by and adds 2 per parameter. B's score minus A's score is . Check: the difference is positive, so B scores worse.
- Choose the lowest score. A has the lower AIC, so these data do not justify the extra parameter.
The plot shows the coin comparison as a function of the gain in log-likelihood that the extra parameter buys. B's AIC minus A's AIC is , so B wins only where that line dips below zero.
- AIC of B minus AIC of A
- tie
The math
The definition (steps 1 and 5)
Let model have free parameters, fitted by maximum likelihood, and let be its maximised log-likelihood: the largest value of the sum of the logs of the probability densities of the observations (see Likelihood Function). Then
The quantity is the deviance of the fitted model, so AIC is the deviance plus twice the number of parameters. Lower is better.
Step 1 in symbols
With observations and density , the log-likelihood is , where is the maximum likelihood estimate. For the coin, is the probability of each flip and the sum has four terms, each equal to . For model A that gives .
Steps 3 and 4 in symbols
Comparing model B with model A:
B is preferred only when its log-likelihood gain is larger than the number of extra parameters . With one extra parameter the gain must exceed 1. The coin gain was , so A wins.
Why the penalty is 2 per parameter
The training log-likelihood is too flattering, as in Overfitting: the estimates were chosen to fit exactly these observations. Akaike's argument, for a large sample and a model close to the truth, is that the average overstatement is approximately . So the expected log-likelihood on new data from the same process is approximately , where the expectation is over new data. Akaike built this on the Kullback–Leibler Divergence between the true process and the model. Multiplying by turns the result into an estimate of the out-of-sample deviance, which equals up to a constant that is the same for every candidate fitted to the same data. That constant can be dropped, because only differences between models matter.
BIC: the same shape, a different penalty
The Bayesian information criterion is . Its penalty per parameter, , grows with the sample size (see Bayesian Information Criterion (BIC)). The plot below shows the two penalties side by side.
- BIC penalty per parameter, ln n
- AIC penalty per parameter
AIC for least squares
For linear regression with Gaussian errors, the maximum likelihood estimate of the noise variance is , where is the residual sum of squares. Substituting this into the log-likelihood and dropping the terms that are the same for every candidate gives
where is the number of regression coefficients plus one for the noise variance. The link to Mallows Cp is that both criteria trade residual error against a penalty per parameter.
Worked examples
Compare A (fair coin, no parameters) with B (unknown , ). The maximum likelihood estimate for B is .
- Log-likelihood of A: .
- Log-likelihood of B: .
- The gain from the extra parameter: .
- AIC for A: . AIC for B: .
- The difference is , so B has the lower AIC by a small margin.
Interpretation: the gain of 1.0465 just clears the penalty of 1 on the log scale, so the extra parameter barely earns its place. With 5 heads in 8 flips the gain would be only 0.25, and A would win. The margin is thin, which is itself a lesson: a small change in the data can reverse the choice.
Four candidate models are fitted to the same 50 observations. Each row gives the number of parameters and the maximised log-likelihood (illustrative numbers):
| Model | ||
|---|---|---|
| A | 2 | -70.0 |
| B | 3 | -62.0 |
| C | 6 | -57.0 |
| D | 8 | -56.5 |
- AIC is . A: . B: . C: . D: .
- The lowest AIC is C, at 126. The order from best to worst is C (126), D (129), B (130), A (144).
- BIC is , with . A: . B: . C: . D: .
- The lowest BIC is B, at 135.74.
Interpretation: C adds three parameters to B and gains 5.0 in log-likelihood. AIC charges 6 for the three parameters and the gain is worth 10 on its scale, so C wins by 4. BIC charges , which is more than the same gain of 10, so B wins. The disagreement comes from the BIC penalty at , which is nearly twice AIC's. D is rejected by both: its two extra parameters over C gain only 0.5 in log-likelihood, which is 1 unit of deviance, short of the 4 that AIC charges for them.
A utility models daily energy use over 100 days. Three least-squares regressions are candidates. Each has an intercept plus the predictors listed, and counts its coefficients plus one for the noise variance (illustrative numbers):
- P: temperature only, 2 coefficients, , .
- Q: temperature, humidity and wind speed, 4 coefficients, , .
- R: Q plus two more predictors, 6 coefficients, , .
- For P: and . So , and adding gives .
- For Q: , , so .
- For R: , , so .
- The lowest AIC is Q. Going from Q to R lowers by , which is less than the 4 charged for the two extra coefficients.
- Try it: suppose R's residual sum of squares had been 380.0 instead of 385.0. Would AIC then prefer R over Q? Answer: R's AIC becomes . That is still above Q's 146.10, so Q remains the choice, though the gap narrows to 1.4.
Interpretation: the middle model wins. The first extra predictors pay for themselves, and the last two do not.
Common mistakes and tradeoffs
It is tempting to think the model with the lowest AIC is the true model. In fact AIC ranks candidates by their estimated predictive quality, and the true process may lie outside all of them. The criterion is a tool for predicting well among the models you have, not a test of which one is correct.
It is tempting to read meaning into the size of an AIC value. In fact only differences matter, because the constants were dropped. Compare models fitted to the same data with the same response. A model of and a model of have different likelihoods, so their AIC values cannot be compared directly.
It is tempting to think AIC always beats BIC, or the reverse. In fact the choice depends on the goal. AIC tends to keep larger models that predict well, and BIC tends to choose smaller ones, which more often recover a true structure, as Example 2 showed.
It is tempting to use AIC unchanged on small samples. In fact the penalty of 2 per parameter is an approximation for large samples. When is small relative to the number of parameters, the corrected criterion AICc adds a term that grows with and gives a more honest penalty. Use AICc when is small compared with .
| Use AIC when | Be careful when |
|---|---|
| The goal is prediction, and the models are fitted by maximum likelihood to the same data | is small relative to the parameters (use AICc) |
| You need a quick comparison without spending data on a validation set | The candidate set is huge, since the winner's score is then optimistic; keep a final test set |
| You want a penalised score that needs no held-out data | The models are far from the truth, where the approximation breaks down; held-out scoring such as Cross-Validation makes no such assumption |
History
Hirotugu Akaike, a Japanese statistician, published the criterion in 1974 in a paper titled "A New Look at the Statistical Model Identification". He framed model choice as estimating the information lost when a fitted model replaces the true process, using the Kullback–Leibler idea of information. Mallows had introduced for choosing regression variables in the early 1970s. Gideon Schwarz published the Bayesian criterion in 1978, derived from an approximation to posterior model probabilities. Both criteria spread slowly among statisticians. Their use grew widely in ecology and biology after Kenneth Burnham and David Anderson's 2002 book, which promoted AIC for comparing several models at once.
Recap
- For nested models, a model's training fit never gets worse as it gains parameters, so fit alone cannot choose between them.
- Training log-likelihood overstates performance on new data by roughly one unit per parameter, for large samples and models close to the truth.
- AIC is . For least squares it is , with including the noise variance.
- Choose the lowest AIC, compare only models fitted to the same data, and use the corrected AICc when the sample is small.
Where it leads next: Bayesian Information Criterion (BIC) changes the penalty to , and Mallows Cp gives the regression-specific version for choosing subsets of variables. AIC is one way to pick a point on the Bias-Variance Tradeoff curve.
Check yourself
QuestionRecall: what does the 2 in AIC = 2d - 2L count, and why does the training log-likelihood need correcting?Show answer
The 2 is the penalty per free parameter. The training log-likelihood needs correcting because the parameters were chosen to fit exactly those observations, so the log-likelihood overstates how well the model will fit new data. Adding a parameter never lowers the training log-likelihood, so without a penalty the most flexible model would always look best.
QuestionComputation: model X has d = 4 and maximised log-likelihood -50. Model Y has d = 6 and maximised log-likelihood -47. Compute AIC for each, and say which is preferred and by how much.Show answer
AIC for X: . AIC for Y: . Y is preferred by 2 units. Its two extra parameters raised the log-likelihood by 3, worth 6 units of deviance, against a penalty of 4, a net gain of 2.
QuestionWhy: BIC's penalty per parameter is ln n, while AIC's is 2. For a sample of 1,000,000 observations, which model does BIC favour when the two criteria disagree, and what does AIC keep that BIC drops?Show answer
, so BIC charges about seven times AIC's penalty per parameter. Where they disagree, BIC favours the smaller model, because it demands a much larger improvement in log-likelihood before it accepts an extra parameter. AIC keeps the smaller real effects that BIC drops, which can help prediction even though they may not be part of a simple true structure.
QuestionApplied: a team has 40 observations and compares 10 candidate regressions with between 4 and 8 parameters each. They choose the lowest AIC and report that model's training error as its performance. What is wrong, and what should they do?Show answer
Two things. The training error is optimistic, because the model was fitted to these 40 observations, so it understates the error on new data. And with only 40 observations and up to 8 parameters, the plain AIC penalty is a weak approximation, so the corrected AICc is the better choice. They should use AICc, or a held-out set, select using only the training part, and report error on data that played no part in choosing, such as a test set or cross-validation.