Search

Search papers and lessons

Akaike Information Criterion

Level 3 · 13 min read

The Akaike information criterion (AIC) scores a fitted model by its fit to the data plus a penalty of 2 per parameter, as an estimate of how well it will predict new data. Lower is better.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Learning basics
  • Calculus
  • Inference
  • Losses & regularization
  • ReadReady to readNot yet

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 pp. Its maximum likelihood estimate is 3/43/4, so it has one free parameter.
  1. Score A by the probability it gives the data. Each flip has probability 1/2, so the four flips together have probability (1/2)4=1/16(1/2)^4 = 1/16. Its log-likelihood is ln⁡(1/16)≈−2.7726\ln(1/16) \approx -2.7726. Check: e−2.7726≈0.0625e^{-2.7726} \approx 0.0625, which is 1/161/16.
  2. Score B at its best value. With p=3/4p = 3/4, one particular sequence, heads, heads, heads, tails, has probability (3/4)3×(1/4)=27/256≈0.1055(3/4)^3 \times (1/4) = 27/256 \approx 0.1055. Its log-likelihood is ln⁡(0.1055)≈−2.2493\ln(0.1055) \approx -2.2493. Check: B fits this data better than A, because it chose pp to suit the data.
  3. Measure the gain from the extra parameter: −2.2493−(−2.7726)=0.5232-2.2493 - (-2.7726) = 0.5232. One extra parameter improved the log-likelihood by only about half a unit.
  4. Charge the penalty. AIC multiplies the log-likelihood by −2-2 and adds 2 per parameter. B's score minus A's score is 2×1−2×0.5232=2−1.0465=0.95352 \times 1 - 2 \times 0.5232 = 2 - 1.0465 = 0.9535. Check: the difference is positive, so B scores worse.
  5. 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 gg in log-likelihood that the extra parameter buys. B's AIC minus A's AIC is 2−2g2 - 2g, so B wins only where that line dips below zero.

00.511.52−2−1012log-likelihood gain g from the extra parameterAIC difference
  • AIC of B minus AIC of A
  • tie
B needs a gain above 1 to win. The coin gain of 0.5232 (marked) leaves B 0.9535 worse, so A is chosen.

The math

The definition (steps 1 and 5)

Definition: Akaike information criterion

Let model MkM_k have dkd_k free parameters, fitted by maximum likelihood, and let L^k\hat{L}_k 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

AICk=2dk−2L^k.\mathrm{AIC}_k = 2d_k - 2\hat{L}_k.

The quantity −2L^k-2\hat{L}_k 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 x1,…,xnx_1, \dots, x_n and density f(x;θ)f(x; \theta), the log-likelihood is L^k=∑i=1nln⁡f(xi;θ^k)\hat{L}_k = \sum_{i=1}^{n} \ln f(x_i; \hat{\theta}_k), where θ^k\hat{\theta}_k is the maximum likelihood estimate. For the coin, ff is the probability of each flip and the sum has four terms, each equal to ln⁡12\ln\frac{1}{2}. For model A that gives 4ln⁡12=−2.77264\ln\frac{1}{2} = -2.7726.

Steps 3 and 4 in symbols

Comparing model B with model A:

AICB−AICA=2(dB−dA)−2(L^B−L^A).\mathrm{AIC}_B - \mathrm{AIC}_A = 2(d_B - d_A) - 2(\hat{L}_B - \hat{L}_A).

B is preferred only when its log-likelihood gain L^B−L^A\hat{L}_B - \hat{L}_A is larger than the number of extra parameters dB−dAd_B - d_A. With one extra parameter the gain must exceed 1. The coin gain was 0.52320.5232, 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 dkd_k. So the expected log-likelihood on new data from the same process is approximately L^k−dk\hat{L}_k - d_k, where the expectation is over new data. Akaike built this on the Kullback–Leibler Divergence between the true process and the model. Multiplying by −2-2 turns the result into an estimate of the out-of-sample deviance, which equals AICk\mathrm{AIC}_k 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 BICk=dkln⁡n−2L^k\mathrm{BIC}_k = d_k \ln n - 2\hat{L}_k. Its penalty per parameter, ln⁡n\ln n, grows with the sample size (see Bayesian Information Criterion (BIC)). The plot below shows the two penalties side by side.

1002003004005000246sample size npenalty per parameter
  • BIC penalty per parameter, ln n
  • AIC penalty per parameter
AIC charges 2 per parameter whatever the sample size. BIC charges ln n, which equals 2 at n of about 7.4 and keeps rising. The marked point is that crossover.

AIC for least squares

For linear regression with Gaussian errors, the maximum likelihood estimate of the noise variance is σ^2=RSS/n\hat{\sigma}^2 = \mathrm{RSS}/n, where RSS\mathrm{RSS} is the residual sum of squares. Substituting this into the log-likelihood and dropping the terms that are the same for every candidate gives

AIC=nln⁡RSSn+2k,\mathrm{AIC} = n\ln\frac{\mathrm{RSS}}{n} + 2k,

where kk 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

Example
A tiny case: eight flips, six heads

Compare A (fair coin, no parameters) with B (unknown pp, dB=1d_B = 1). The maximum likelihood estimate for B is p^=6/8=0.75\hat{p} = 6/8 = 0.75.

  1. Log-likelihood of A: 8ln⁡12=−5.54528\ln\frac{1}{2} = -5.5452.
  2. Log-likelihood of B: 6ln⁡0.75+2ln⁡0.25=6(−0.2877)+2(−1.3863)=−1.7261−2.7726=−4.49876\ln 0.75 + 2\ln 0.25 = 6(-0.2877) + 2(-1.3863) = -1.7261 - 2.7726 = -4.4987.
  3. The gain from the extra parameter: −4.4987−(−5.5452)=1.0465-4.4987 - (-5.5452) = 1.0465.
  4. AIC for A: −2(−5.5452)=11.0904-2(-5.5452) = 11.0904. AIC for B: 2(1)−2(−4.4987)=2+8.9974=10.99742(1) - 2(-4.4987) = 2 + 8.9974 = 10.9974.
  5. The difference is 11.0904−10.9974=0.093011.0904 - 10.9974 = 0.0930, 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.

Example
Standard case: four candidates on 50 observations

Four candidate models are fitted to the same 50 observations. Each row gives the number of parameters dd and the maximised log-likelihood L^\hat{L} (illustrative numbers):

ModelddL^\hat{L}
A2-70.0
B3-62.0
C6-57.0
D8-56.5
  1. AIC is 2d−2L^2d - 2\hat{L}. A: 4+140=1444 + 140 = 144. B: 6+124=1306 + 124 = 130. C: 12+114=12612 + 114 = 126. D: 16+113=12916 + 113 = 129.
  2. The lowest AIC is C, at 126. The order from best to worst is C (126), D (129), B (130), A (144).
  3. BIC is dln⁡50−2L^d\ln 50 - 2\hat{L}, with ln⁡50≈3.9120\ln 50 \approx 3.9120. A: 7.8240+140=147.827.8240 + 140 = 147.82. B: 11.7361+124=135.7411.7361 + 124 = 135.74. C: 23.4721+114=137.4723.4721 + 114 = 137.47. D: 31.2962+113=144.3031.2962 + 113 = 144.30.
  4. 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 3×3.912=11.743 \times 3.912 = 11.74, which is more than the same gain of 10, so B wins. The disagreement comes from the BIC penalty at n=50n = 50, 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.

Example
Realistic case: daily energy use with three regressions

A utility models daily energy use over 100 days. Three least-squares regressions are candidates. Each has an intercept plus the predictors listed, and kk counts its coefficients plus one for the noise variance (illustrative numbers):

  • P: temperature only, 2 coefficients, k=3k = 3, RSS=420.0\mathrm{RSS} = 420.0.
  • Q: temperature, humidity and wind speed, 4 coefficients, k=5k = 5, RSS=390.0\mathrm{RSS} = 390.0.
  • R: Q plus two more predictors, 6 coefficients, k=7k = 7, RSS=385.0\mathrm{RSS} = 385.0.
  1. For P: RSS/n=4.20\mathrm{RSS}/n = 4.20 and ln⁡4.20≈1.4351\ln 4.20 \approx 1.4351. So nln⁡(RSS/n)=143.51n\ln(\mathrm{RSS}/n) = 143.51, and adding 2k=62k = 6 gives AIC=149.51\mathrm{AIC} = 149.51.
  2. For Q: RSS/n=3.90\mathrm{RSS}/n = 3.90, ln⁡3.90≈1.3610\ln 3.90 \approx 1.3610, so 136.10+10=146.10136.10 + 10 = 146.10.
  3. For R: RSS/n=3.85\mathrm{RSS}/n = 3.85, ln⁡3.85≈1.3481\ln 3.85 \approx 1.3481, so 134.81+14=148.81134.81 + 14 = 148.81.
  4. The lowest AIC is Q. Going from Q to R lowers nln⁡(RSS/n)n\ln(\mathrm{RSS}/n) by 136.10−134.81=1.29136.10 - 134.81 = 1.29, which is less than the 4 charged for the two extra coefficients.
  5. 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 100ln⁡3.80+14≈133.50+14=147.50100\ln 3.80 + 14 \approx 133.50 + 14 = 147.50. 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 ln⁡y\ln y and a model of yy 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 nn is small relative to the number of parameters, the corrected criterion AICc adds a term that grows with d2d^2 and gives a more honest penalty. Use AICc when nn is small compared with dd.

Use AIC whenBe careful when
The goal is prediction, and the models are fitted by maximum likelihood to the same datann is small relative to the parameters (use AICc)
You need a quick comparison without spending data on a validation setThe 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 dataThe 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 CpC_p 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 2d−2L^2d - 2\hat{L}. For least squares it is nln⁡(RSS/n)+2kn\ln(\mathrm{RSS}/n) + 2k, with kk 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 dln⁡nd\ln n, 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: 2(4)−2(−50)=8+100=1082(4) - 2(-50) = 8 + 100 = 108. AIC for Y: 2(6)−2(−47)=12+94=1062(6) - 2(-47) = 12 + 94 = 106. 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

ln⁡1,000,000≈13.8\ln 1{,}000{,}000 \approx 13.8, 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.

Sources