Simple Algorithm
Machine Learning · Convergence · 26 min

The Bias–Variance Decomposition

An exact identity for squared loss, and what replaces it for 0–1 loss.

For squared loss, the expected error of any learner splits exactly into noise, squared bias and variance. Change the loss and the identity changes with it: log loss needs a geometric average, and under the 0–1 loss of classification, variance can even lower the error. This lesson proves the identity in full generality, derives what replaces it for other losses, and looks at what ensembles and very wide networks do to the variance term.

What you’ll learn

  • State and prove the decomposition with random data and random training (seeds), and relate integrated bias² and variance to approximation and estimation error.
  • Derive the log-loss decomposition around the normalized geometric mean, and the general version for Bregman divergences.
  • Prove Domingos' decomposition of the two-class 0–1 loss, explain why variance is subtractive on biased points, and compare it with the Kohavi–Wolpert, James and Friedman analyses.
  • Compute the variance of an averaged ensemble and the ambiguity decomposition, and summarize the evidence on variance in wide networks.

The identity in full generality

Let PP be a distribution on X×R\mathcal X\times\R, D∼Pn\data\sim P^n a training set, and ξ\xi the learner's internal randomness (initialization, data order, dropout masks), independent of D\data. The learner outputs f^=f^D,ξ\hat f=\hat f_{\data,\xi}. A test pair (x,y)∼P(\mathbf x,y)\sim P is independent of (D,ξ)(\data,\xi). Write f⋆(x)=E[y∣x]f^\star(\mathbf x)=\E[y\mid\mathbf x] for the regression function, σ2(x)=Var⁡(y∣x)\sigma^2(\mathbf x)=\Var(y\mid\mathbf x) for the noise, fˉ(x)=ED,ξ[f^(x)]\bar f(\mathbf x)=\E_{\data,\xi}\big[\hat f(\mathbf x)\big] for the average prediction, and ∥g∥2=Ex[g(x)2]\norm{g}^2=\E_{\mathbf x}[g(\mathbf x)^2].

DerivationProof
  1. E[(y−f^)2∣x]=E[(y−f⋆)2∣x]+E[(f⋆−f^)2∣x]+2 E[(y−f⋆)(f⋆−f^)∣x]\E\big[(y-\hat f)^2\mid\mathbf x\big]=\E\big[(y-f^\star)^2\mid\mathbf x\big]+\E\big[(f^\star-\hat f)^2\mid\mathbf x\big]+2\,\E\big[(y-f^\star)(f^\star-\hat f)\mid\mathbf x\big]

    Expand around f⋆f^\star. Given x\mathbf x, the label is independent of (D,ξ)(\data,\xi) and E[y−f⋆(x)∣x,D,ξ]=0\E[y-f^\star(\mathbf x)\mid\mathbf x,\data,\xi]=0, so the cross term has zero conditional mean:

  2. ED,ξ[(f⋆−f^)2]=(f⋆−fˉ)2+ED,ξ[(fˉ−f^)2]\E_{\data,\xi}\big[(f^\star-\hat f)^2\big]=(f^\star-\bar f)^2+\E_{\data,\xi}\big[(\bar f-\hat f)^2\big]

    The first term is σ2(x)\sigma^2(\mathbf x) and the cross term is 00. Inserting fˉ\bar f in the second term, the new cross term vanishes because ED,ξ[f^(x)−fˉ(x)]=0\E_{\data,\xi}[\hat f(\mathbf x)-\bar f(\mathbf x)]=0 while f⋆−fˉf^\star-\bar f is fixed:

  3. E[R(f^)]−R⋆=∥fˉ−f⋆∥2⏟integrated bias2+E∥f^−fˉ∥2⏟integrated variance\E\big[R(\hat f)\big]-R^\star=\underbrace{\norm{\bar f-f^\star}^2}_{\text{integrated bias}^2}+\underbrace{\E\norm{\hat f-\bar f}^2}_{\text{integrated variance}}

    Integrate over x\mathbf x. For squared loss, R(g)−R⋆=∥g−f⋆∥2R(g)-R^\star=\norm{g-f^\star}^2 for every gg, which is the form used below.

Training randomness adds a source of variance that the classical picture, with a deterministic learner, leaves out. By the law of total variance,

Var⁡D,ξ(f^(x))=EDVar⁡ξ(f^(x)∣D)⏟optimization variance+Var⁡DEξ(f^(x)∣D)⏟sampling variance.\Var_{\data,\xi}\big(\hat f(\mathbf x)\big)=\underbrace{\E_\data\Var_\xi\big(\hat f(\mathbf x)\mid\data\big)}_{\text{optimization variance}}+\underbrace{\Var_\data\E_\xi\big(\hat f(\mathbf x)\mid\data\big)}_{\text{sampling variance}}.

Averaging models trained from many seeds on the same data removes exactly the first term and leaves the bias untouched; this is one way to read the gains of deep ensembles. The split depends on the order of conditioning (condition on ξ\xi first and both terms change, though their sum does not), which is why Adlam & Pennington (2020) use a finer decomposition with separate terms for sampling, initialization, label noise and their interactions.

Other losses: the right average

The squared-loss proof used one property: the arithmetic mean fˉ\bar f makes the cross term vanish. Other losses need a different average. For log loss a predictor outputs a distribution qq over KK classes; at a fixed x\mathbf x with true conditional distribution pp, its expected loss is Ey∼p[−log⁡q(y)]=H(p)+DKL(p ∥ q)\E_{y\sim p}[-\log q(y)]=H(p)+\KL(p\,\|\,q). Heskes (1998) showed that the decomposition survives if the average model is the normalized geometric mean

q~(y)=1Zexp⁡(EDlog⁡qD(y)),Z=∑yexp⁡(EDlog⁡qD(y))≤1,\tilde q(y)=\frac1Z\exp\big(\E_\data\log q_\data(y)\big),\qquad Z=\sum_{y}\exp\big(\E_\data\log q_\data(y)\big)\le1,

where Z≤1Z\le1 follows from Jensen's inequality, exp⁡(Elog⁡q)≤Eq\exp(\E\log q)\le\E q.

DerivationLog loss: noise + KL bias + KL variance
  1. EDDKL(p ∥ qD)=∑yp(y)log⁡p(y)−∑yp(y) EDlog⁡qD(y)=DKL(p ∥ q~)−log⁡Z\E_\data\KL(p\,\|\,q_\data)=\sum_yp(y)\log p(y)-\sum_yp(y)\,\E_\data\log q_\data(y)=\KL(p\,\|\,\tilde q)-\log Z

    Average the KL term over training sets and substitute EDlog⁡qD(y)=log⁡q~(y)+log⁡Z\E_\data\log q_\data(y)=\log\tilde q(y)+\log Z:

  2. EDDKL(q~ ∥ qD)=∑yq~(y)log⁡q~(y)−∑yq~(y)(log⁡q~(y)+log⁡Z)=−log⁡Z\E_\data\KL(\tilde q\,\|\,q_\data)=\sum_y\tilde q(y)\log\tilde q(y)-\sum_y\tilde q(y)\big(\log\tilde q(y)+\log Z\big)=-\log Z

    The same substitution identifies −log⁡Z-\log Z as an average divergence of the individual models from their geometric mean, which is nonnegative:

  3. ED,y[−log⁡qD(y)]=H(p)⏟noise+DKL(p ∥ q~)⏟bias+EDDKL(q~ ∥ qD)⏟variance\E_{\data,y}\big[-\log q_\data(y)\big]=\underbrace{H(p)}_{\text{noise}}+\underbrace{\KL(p\,\|\,\tilde q)}_{\text{bias}}+\underbrace{\E_\data\KL(\tilde q\,\|\,q_\data)}_{\text{variance}}

    Put the pieces together. All three terms are nonnegative, and the identity holds pointwise in x\mathbf x:

Both cases are instances of one identity. For a Bregman divergence Dφ(a,b)=φ(a)−φ(b)−⟨∇φ(b),a−b⟩D_\varphi(a,b)=\varphi(a)-\varphi(b)-\langle\nabla\varphi(b),a-b\rangle used as the loss Dφ(y,y^)D_\varphi(y,\hat y), the three-point identity Dφ(a,c)=Dφ(a,b)+Dφ(b,c)+⟨∇φ(b)−∇φ(c),a−b⟩D_\varphi(a,c)=D_\varphi(a,b)+D_\varphi(b,c)+\langle\nabla\varphi(b)-\nabla\varphi(c),a-b\rangle gives

E Dφ(y,y^)=E Dφ(y,yˉ)+Dφ(yˉ,y^∘)+E Dφ(y^∘,y^),yˉ=Ey,∇φ(y^∘)=E ∇φ(y^),\E\,D_\varphi(y,\hat y)=\E\,D_\varphi(y,\bar y)+D_\varphi(\bar y,\hat y^\circ)+\E\,D_\varphi(\hat y^\circ,\hat y),\qquad \bar y=\E y,\quad \nabla\varphi(\hat y^\circ)=\E\,\nabla\varphi(\hat y),

with yy independent of y^\hat y. The target is averaged in the primal coordinates and the predictions in the dual ones. Squared loss has ∇φ\nabla\varphi linear, so both averages are arithmetic; for KL on the simplex, ∇φ=log⁡\nabla\varphi=\log (up to constants), and the dual average is the normalized geometric mean.

Check your understanding

Two models predict, at some input, the class distributions (0.9,0.1)(0.9,0.1) and (0.1,0.9)(0.1,0.9). In Heskes' decomposition, what is their "average model" q~\tilde q?

  1. (0.5,0.5)(0.5,0.5), and its variance term is −log⁡Z=−log⁡0.6≈0.51-\log Z=-\log 0.6\approx0.51 nats
  2. (0.5,0.5)(0.5,0.5), with variance term 00 because the models are symmetric
  3. (0.9,0.9)(0.9,0.9), the elementwise maximum
  4. It is undefined, because the two models disagree
Show the answer

A. (0.5,0.5)(0.5,0.5), and its variance term is −log⁡Z=−log⁡0.6≈0.51-\log Z=-\log 0.6\approx0.51 nats

The geometric means are 0.9⋅0.1=0.3\sqrt{0.9\cdot0.1}=0.3 for both classes, so Z=0.6Z=0.6 and q~=(0.5,0.5)\tilde q=(0.5,0.5). The variance term is −log⁡Z=log⁡(5/3)≈0.51-\log Z=\log(5/3)\approx0.51 nats, the average KL divergence from q~\tilde q to each model: large, because the two models disagree sharply.

0–1 loss: no clean split

Fix x\mathbf x in a two-class problem with η=P(y=1∣x)\eta=P(y=1\mid\mathbf x). The Bayes prediction is y⋆=1{η≥12}y^\star=\mathbf 1\{\eta\ge\frac12\} and the noise is N=min⁡(η,1−η)N=\min(\eta,1-\eta). The learner predicts y^D∈{0,1}\hat y_\data\in\{0,1\}. Domingos (2000) defines the main prediction ymy_m as the most frequent prediction over training sets (the minimizer of average loss to the predictions, which for 0–1 loss is the mode), the bias B=1{ym≠y⋆}B=\mathbf 1\{y_m\ne y^\star\} and the variance V=PD(y^D≠ym)≤12V=P_\data(\hat y_\data\ne y_m)\le\frac12.

DerivationProof
  1. P(y≠y^D)=(1−e)N+e(1−N)=N+e (1−2N)P(y\ne\hat y_\data)=(1-e)N+e(1-N)=N+e\,(1-2N)

    Given x\mathbf x, the test label and the prediction are independent. Let e=PD(y^D≠y⋆)e=P_\data(\hat y_\data\ne y^\star). The prediction is wrong if it matches y⋆y^\star while yy does not, or the reverse:

  2. e=B+c2Ve=B+c_2V

    If the main prediction is right (B=0B=0), the prediction errs exactly when it deviates from ymy_m, so e=Ve=V. If it is wrong (B=1B=1), the prediction is right exactly when it deviates, so e=1−Ve=1-V. In both cases:

  3. N+e−2eN=(1−2e)N+e=c1N+B+c2VN+e-2eN=(1-2e)N+e=c_1N+B+c_2V

    Substitute and use c1=1−2ec_1=1-2e. As a bonus, the excess over the Bayes error at x\mathbf x is e (1−2N)=e ∣2η−1∣e\,(1-2N)=e\,\abs{2\eta-1}: mistakes where η≈12\eta\approx\frac12 cost almost nothing.

On an unbiased point, variance adds to the error as it does for squared loss. On a biased point it subtracts: when most training sets lead to the wrong class, a learner that wobbles is right more often. Averaged over x\mathbf x, the error is a weighted noise term Ex[c1N]\E_{\mathbf x}[c_1N], plus the average bias, plus a net variance Ex[c2V]\E_{\mathbf x}[c_2V] in which the two kinds of points partly cancel. Domingos uses this to explain why highly unstable learners such as decision trees can do well on 0–1 loss.

Friedman (1997) looked at the same phenomenon through the probability estimate η^D(x)\hat\eta_\data(\mathbf x) that a classifier thresholds at 12\frac12. If η^D(x)\hat\eta_\data(\mathbf x) is approximately N(m,s2)\mathcal N(m,s^2) over training sets, then

PD(y^D≠y⋆)≈Φ(sign⁡(12−η) m−12s).P_\data\big(\hat y_\data\ne y^\star\big)\approx\Phi\Big(\sign\big(\tfrac12-\eta\big)\,\frac{m-\frac12}{s}\Big).

Bias enters only through the side of 12\frac12 on which mm falls, and it interacts with the variance rather than adding to it. Low-variance probability estimates can be badly biased and still classify well, which helps explain why simple methods such as naive Bayes and nearest neighbors can classify well even when their probability estimates are poor.

Check your understanding

At a point with η=0.7\eta=0.7, a learner's probability estimates are approximately N(0.45, 0.12)\mathcal N(0.45,\,0.1^2) over training sets. You halve their standard deviation, keeping the mean. What happens to P(y^≠y⋆)P(\hat y\ne y^\star)?

  1. It falls from about 0.69 to about 0.50
  2. It rises from about 0.69 to about 0.84
  3. It falls from about 0.31 to about 0.16
  4. It is unchanged, since the mean is unchanged
Show the answer

B. It rises from about 0.69 to about 0.84

The mean 0.450.45 is on the wrong side of 12\frac12 (the Bayes class is 1). The error probability is Φ((0.5−0.45)/s)\Phi\big((0.5-0.45)/s\big): Φ(0.5)≈0.69\Phi(0.5)\approx0.69 at s=0.1s=0.1 and Φ(1)≈0.84\Phi(1)\approx0.84 at s=0.05s=0.05. On the wrong side of the boundary, less variance means the wrong answer more consistently.

ProposalDefinitionsStrengthWeakness
Kohavi & Wolpert (1996)squared-loss identity applied to one-hot class vectors: noise 12(1−∑ypy2)\frac12(1-\sum_yp_y^2), bias² 12∑y(py−qy)2\frac12\sum_y(p_y-q_y)^2, variance 12(1−∑yqy2)\frac12(1-\sum_yq_y^2), with pp the label and qq the prediction distributionexactly additive, variance ≥0\ge0the Bayes classifier can have nonzero bias, and the noise term is not the Bayes error
Domingos (2000)main prediction = mode; BB and VV as abovenoise is the Bayes error; one definition for all lossescoefficients c1c_1, c2c_2 depend on the learner; variance subtracts on biased points
James (2003)bias and variance as properties of the predictor; systematic effect and variance effect as their effect on the errorthe telescoping identity EL=noise+SE+VE\E L=\text{noise}+\text{SE}+\text{VE} holds for any lossSE and VE equal bias² and variance only for squared loss
Friedman (1997)bias and variance of the class-probability estimateexplains when biased probability estimates classify wellrelies on an approximation; no exact additive split
Desirable properties: an additive split, nonnegative terms, noise equal to the Bayes error, zero bias for the Bayes classifier, and variance that always costs. None of the four proposals delivers all of them at once; each keeps some.
Predict before you look

At a point with P(y=1∣x)=0.8P(y=1\mid\mathbf x)=0.8, the Bayes classifier always predicts 1. What is its Kohavi–Wolpert bias² term?

Show the answer

0.04

With p=(0.2,0.8)p=(0.2,0.8) and q=(0,1)q=(0,1): bias² =12[(0.2)2+(0.2)2]=0.04=\frac12\big[(0.2)^2+(0.2)^2\big]=0.04, noise =12(1−0.04−0.64)=0.16=\frac12(1-0.04-0.64)=0.16, variance =0=0. The total, 0.200.20, is the Bayes error, but it is split as 0.160.16 "noise" plus 0.040.04 "bias" for a classifier that could not be improved.

Ensembles: averaging away variance

DerivationVariance of an average of correlated predictors
  1. Var⁡(1B∑b=1Bf^b)=1B2(Bs2+B(B−1)ρs2)=ρs2+1−ρB s2\Var\Big(\frac1B\sum_{b=1}^B\hat f_b\Big)=\frac1{B^2}\Big(Bs^2+B(B-1)\rho s^2\Big)=\rho s^2+\frac{1-\rho}{B}\,s^2

    Let f^1,…,f^B\hat f_1,\dots,\hat f_B be identically distributed at x\mathbf x, each with variance s2s^2 and pairwise correlation ρ\rho. Their average has the same mean, so the same bias, and variance

  2. lim⁡B→∞Var⁡(1B∑bf^b)=ρ s2\lim_{B\to\infty}\Var\Big(\frac1B\sum_b\hat f_b\Big)=\rho\,s^2

    As B→∞B\to\infty the variance falls to ρs2\rho s^2, not to zero: the correlation sets the floor. Bagging (Breiman, 1996) builds the f^b\hat f_b on bootstrap resamples; random forests also lower ρ\rho by restricting each split to a random subset of features.

  3. (fˉw−y)2=∑iwi(f^i−y)2−∑iwi(f^i−fˉw)2(\bar f_w-y)^2=\sum_iw_i(\hat f_i-y)^2-\sum_iw_i(\hat f_i-\bar f_w)^2

    For a weighted ensemble fˉw=∑iwif^i\bar f_w=\sum_iw_i\hat f_i (wi≥0w_i\ge0, ∑iwi=1\sum_iw_i=1), expanding ∑iwi(f^i−y)2\sum_iw_i(\hat f_i-y)^2 around fˉw\bar f_w gives the ambiguity decomposition (Krogh & Vedelsby, 1995), for every single example: the ensemble's squared error is the average member error minus the members' spread.

Think first Under squared loss an averaged ensemble is never worse than its average member. Is a majority vote under 0–1 loss also never worse than its average member?

No. Take three classifiers and six test points, each classifier wrong on two points: the first on points 1 and 2, the second on 1 and 3, the third on 2 and 3. Each member errs on 1/31/3 of the points, but on points 1, 2 and 3 two of the three are wrong, so the vote errs on 1/21/2. In Domingos' terms, voting moves every point toward its main prediction: it removes variance, which helps where the main prediction is right and hurts where it is wrong.

Variance in wide networks

The classical picture says variance grows with capacity. Measurements on neural networks disagree. Neal et al. (2018) trained networks of increasing width and found that "both bias and variance can decrease as the number of parameters grows," splitting the variance into an optimization part and a sampling part as above. Yang, Yu, You, Steinhardt & Ma (2020) measured a monotonically decreasing bias and a unimodal variance that first rises and then falls with width. Their sum, the risk, takes different shapes depending on the relative sizes of the two terms, and the double-descent curve is one special case.

In a solvable random-features model, Adlam & Pennington (2020) showed that variance terms can diverge at the interpolation threshold even without label noise, through the interaction of sampling and initialization, and that averaging over either source (bagging, or ensembling over initializations) removes the divergence. The identity of this lesson is untouched by all of this; what changed is the belief that variance must grow with the number of parameters.

Key takeaways

  • For squared loss, ER(f^)=R⋆+∥fˉ−f⋆∥2+E∥f^−fˉ∥2\E R(\hat f)=R^\star+\norm{\bar f-f^\star}^2+\E\norm{\hat f-\bar f}^2 for every learner, with training randomness included; for convex classes, integrated bias² is at least the approximation error and variance at most the estimation error.
  • Other losses need other averages: log loss decomposes around the normalized geometric mean (Heskes), and every Bregman divergence around the dual-coordinate mean of the predictions.
  • For two-class 0–1 loss, EL=c1N+B+c2V\E L=c_1N+B+c_2V with c2=−1c_2=-1 on biased points (Domingos): variance can lower classification error, and bias in probability estimates matters only through the side of 12\frac12 it falls on (Friedman).
  • Averaging BB predictors with correlation ρ\rho leaves the bias and cuts the variance to ρs2+(1−ρ)s2/B\rho s^2+(1-\rho)s^2/B; the ambiguity decomposition shows why diversity helps under squared loss, and majority votes can still hurt under 0–1 loss.
  • In wide networks, measured variance eventually falls with width; the decomposition holds, the monotone trade-off does not.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

In the bias–variance decomposition of log loss, which "average model" makes the cross term vanish?

  1. The arithmetic mean of the predicted distributions
  2. The most frequent predicted class
  3. The normalized geometric mean of the predicted distributions
  4. The median of the predicted probabilities
Show the answer

C. The normalized geometric mean of the predicted distributions

With q~∝exp⁡(EDlog⁡qD)\tilde q\propto\exp(\E_\data\log q_\data), the expected KL splits into DKL(p ∥ q~)\KL(p\,\|\,\tilde q) plus EDDKL(q~ ∥ qD)=−log⁡Z\E_\data\KL(\tilde q\,\|\,q_\data)=-\log Z. In Bregman terms, predictions are averaged in the dual coordinates, which for KL are logarithms.

Question 2

At a test point, 70% of the training sets lead a classifier to predict the wrong class (relative to the Bayes prediction). According to Domingos' decomposition, what does a modest increase in the learner's variance at that point do to the expected 0–1 loss there?

  1. It lowers it
  2. It raises it, as variance always does
  3. Nothing, because variance only affects unbiased points
  4. It raises the noise term
Show the answer

A. It lowers it

The point is biased (B=1B=1), so c2=−1c_2=-1 and the loss is c1N+1−Vc_1N+1-V: more variance means more training sets predict the correct class. The excess error e ∣2η−1∣e\,\abs{2\eta-1} falls as e=1−Ve=1-V falls.

Question 3

Each tree in a bagged ensemble has variance s2=1s^2=1 at a point, with pairwise correlation ρ=0.5\rho=0.5. What does the ensemble's variance approach as the number of trees grows without bound?

  1. 00
  2. 0.250.25
  3. 0.50.5
  4. 11
Show the answer

C. 0.50.5

ρs2+(1−ρ)s2/B→ρs2=0.5\rho s^2+(1-\rho)s^2/B\to\rho s^2=0.5. Only decorrelating the trees (smaller ρ\rho), as random forests do, lowers the floor further.

Question 4

A least-squares learner outputs linear functions of fixed features, a convex class H\mathcal H that contains the average prediction fˉ\bar f. How does its integrated squared bias compare with the approximation error R(f∘)−R⋆R(f^\circ)-R^\star?

  1. It is always smaller
  2. It is at least as large, with equality exactly when fˉ\bar f is a best-in-class predictor
  3. They are always equal
  4. They are unrelated
Show the answer

B. It is at least as large, with equality exactly when fˉ\bar f is a best-in-class predictor

Integrated bias² equals R(fˉ)−R⋆R(\bar f)-R^\star, and since fˉ∈H\bar f\in\mathcal H, R(fˉ)≥R(f∘)R(\bar f)\ge R(f^\circ). For unregularized least squares the gap comes only from finite-sample effects (with a fixed design and in-sample error it is exactly zero); ridge adds shrinkage bias on top of the approximation error.

Further reading

  • P. Domingos, "A unified bias-variance decomposition and its applications," Proceedings of the 17th International Conference on Machine Learning (ICML), 231–238 (2000).
  • R. Kohavi & D. H. Wolpert, "Bias plus variance decomposition for zero-one loss functions," Proceedings of the 13th International Conference on Machine Learning (ICML) (1996).
  • J. H. Friedman, "On bias, variance, 0/1-loss, and the curse-of-dimensionality," Data Mining and Knowledge Discovery 1(1), 55–77 (1997).
  • T. Heskes, "Bias/variance decompositions for likelihood-based estimators," Neural Computation 10(6), 1425–1433 (1998).
  • Z. Yang, Y. Yu, C. You, J. Steinhardt & Y. Ma, "Rethinking bias-variance trade-off for generalization of neural networks," Proceedings of the 37th International Conference on Machine Learning, PMLR 119, 10767–10777 (2020).