Simple Algorithm
Machine Learning · Convergence · 28 min

Risk, Bayes Optimality & Excess Risk

The best possible predictor, and how far learned ones fall short.

Every guarantee in classification is, in the end, a statement about one gap: how far a learned classifier's error sits above the Bayes error. This lesson computes that gap exactly, bounds it for plug-in rules, meets the theorems that some rules close it for every distribution while no rate of closing holds for all of them, and characterizes the convex losses whose minimization provably leads to the Bayes classifier.

What you’ll learn

  • Prove the excess-risk identity R(g)−R∗=E[∣2η(x)−1∣ 1{g(x)≠g∗(x)}]R(g)-R^*=\E\big[\abs{2\eta(\mathbf x)-1}\,\mathbf 1\{g(\mathbf x)\ne g^*(\mathbf x)\}\big] and compute Bayes errors.
  • Bound plug-in classifiers by 2 E∣η^−η∣2\,\E\abs{\hat\eta-\eta}, and show how a margin condition turns an estimation error ε\varepsilon into an excess risk of order ε1+α\varepsilon^{1+\alpha}.
  • Define consistency and universal consistency, state Stone's theorem and Devroye's no-universal-rate theorem, and connect them to the approximation–estimation trade-off.
  • Define classification calibration, compute the ψ\psi-transform of standard surrogates, and turn a bound on surrogate excess risk into a bound on excess 0–1 risk.

The Bayes classifier, exactly

Take binary labels y∈{0,1}y\in\{0,1\} and the regression function η(x)=P(y=1∣x)\eta(\mathbf x)=P(y=1\mid\mathbf x). A classifier is a measurable g:X→{0,1}g:\mathcal X\to\{0,1\} with risk R(g)=P(g(x)≠y)R(g)=P(g(\mathbf x)\ne y). The Bayes classifier is g∗(x)=1{η(x)>1/2}g^*(\mathbf x)=\mathbf 1\{\eta(\mathbf x)>1/2\}, its risk R∗R^* is the Bayes error, and R(g)−R∗R(g)-R^* is the excess risk of gg.

DerivationProof
  1. P(g(x)≠y∣x)=η(x) 1{g(x)=0}+(1−η(x)) 1{g(x)=1}P\big(g(\mathbf x)\ne y\mid\mathbf x\big)=\eta(\mathbf x)\,\mathbf 1\{g(\mathbf x)=0\}+\big(1-\eta(\mathbf x)\big)\,\mathbf 1\{g(\mathbf x)=1\}

    Condition on x\mathbf x. Predicting 11 is wrong when y=0y=0, predicting 00 is wrong when y=1y=1:

  2. P(g(x)≠y∣x)−P(g∗(x)≠y∣x)=∣2η(x)−1∣ 1{g(x)≠g∗(x)}P\big(g(\mathbf x)\ne y\mid\mathbf x\big)-P\big(g^*(\mathbf x)\ne y\mid\mathbf x\big)=\abs{2\eta(\mathbf x)-1}\,\mathbf 1\{g(\mathbf x)\ne g^*(\mathbf x)\}

    Where gg and g∗g^* agree, their conditional errors coincide. Where they disagree, g∗g^* pays min⁡(η,1−η)\min(\eta,1-\eta) and gg pays max⁡(η,1−η)\max(\eta,1-\eta), so the difference is ∣η−(1−η)∣\abs{\eta-(1-\eta)}:

  3. R(g)−R∗=E[∣2η(x)−1∣ 1{g(x)≠g∗(x)}]R(g)-R^*=\E\Big[\abs{2\eta(\mathbf x)-1}\,\mathbf 1\{g(\mathbf x)\ne g^*(\mathbf x)\}\Big]

    Average over x\mathbf x. The integrand is nonnegative, so R(g)≥R∗R(g)\ge R^*. The conditional error of g∗g^* is min⁡(η,1−η)=12−12∣2η−1∣\min(\eta,1-\eta)=\tfrac12-\tfrac12\abs{2\eta-1}, which gives the formula for R∗R^*.

The weight ∣2η−1∣\abs{2\eta-1} is the heart of the matter. A wrong decision where η(x)\eta(\mathbf x) is near 1/21/2 costs almost nothing; a wrong decision where the label is nearly certain costs almost one full unit. With KK classes and ηk(x)=P(y=k∣x)\eta_k(\mathbf x)=P(y=k\mid\mathbf x) the same argument gives R(g)−R∗=E[max⁡kηk(x)−ηg(x)(x)]R(g)-R^*=\E\big[\max_k\eta_k(\mathbf x)-\eta_{g(\mathbf x)}(\mathbf x)\big].

Predict before you look

The two classes are equally likely, and given the class the input is Gaussian: x∣y=0∼N(−1,1)x\mid y=0\sim\mathcal N(-1,1) and x∣y=1∼N(1,1)x\mid y=1\sim\mathcal N(1,1). What is the Bayes error, in percent?

Show the answer

15.9 %

Bayes' rule gives η(x)=e−(x−1)2/2e−(x−1)2/2+e−(x+1)2/2=11+e−2x\eta(x)=\dfrac{e^{-(x-1)^2/2}}{e^{-(x-1)^2/2}+e^{-(x+1)^2/2}}=\dfrac1{1+e^{-2x}}, so g∗g^* predicts 11 exactly when x>0x>0. Each class errs when its input lands on the wrong side of 00, which for N(1,1)\mathcal N(1,1) has probability Φ(−1)≈0.159\Phi(-1)\approx0.159 (Φ\Phi is the standard normal distribution function). With class means ±μ\pm\mu the Bayes error is Φ(−μ)\Phi(-\mu): never zero, because the two densities overlap everywhere.

Plug-in rules and the margin

Many classifiers are, at heart, estimates of η\eta. Logistic regression, kk-nearest-neighbor averages and kernel smoothers all output a number η^(x)∈[0,1]\hat\eta(\mathbf x)\in[0,1], and the plug-in rule predicts g^(x)=1{η^(x)>1/2}\hat g(\mathbf x)=\mathbf 1\{\hat\eta(\mathbf x)>1/2\}. How good must η^\hat\eta be?

DerivationProof
  1. g^(x)≠g∗(x) ⟹ ∣2η(x)−1∣=2 ∣η(x)−12∣≤2 ∣η(x)−η^(x)∣\hat g(\mathbf x)\ne g^*(\mathbf x)\ \Longrightarrow\ \abs{2\eta(\mathbf x)-1}=2\,\big|\eta(\mathbf x)-\tfrac12\big|\le2\,\abs{\eta(\mathbf x)-\hat\eta(\mathbf x)}

    Where g^≠g∗\hat g\ne g^*, the numbers η(x)\eta(\mathbf x) and η^(x)\hat\eta(\mathbf x) lie on opposite sides of 1/21/2 (one may equal it), so η\eta is at least as close to 1/21/2 as to η^\hat\eta:

  2. R(g^)−R∗≤2 E[∣η−η^∣ 1{g^≠g∗}]≤2 E∣η−η^∣≤2E(η−η^)2R(\hat g)-R^*\le2\,\E\Big[\abs{\eta-\hat\eta}\,\mathbf 1\{\hat g\ne g^*\}\Big]\le2\,\E\abs{\eta-\hat\eta}\le2\sqrt{\E(\eta-\hat\eta)^2}

    Insert this into the excess-risk identity, drop the indicator, and apply Jensen's inequality for the second form:

The bound wastes something: it charges the estimation error everywhere, although mistakes happen only where η^\hat\eta lands on the wrong side of 1/21/2, and they are cheap where η\eta is close to 1/21/2. A margin (or low-noise) condition, in the style of Mammen and Tsybakov (1999) and Tsybakov (2004), limits how much probability sits near the decision boundary: for some C>0C>0 and α≥0\alpha\ge0,

P(0<∣η(x)−12∣≤t)≤C tαfor all t>0.P\Big(0<\big|\eta(\mathbf x)-\tfrac12\big|\le t\Big)\le C\,t^{\alpha}\qquad\text{for all }t>0.

With α=0\alpha=0 (and C=1C=1) it says nothing; large α\alpha means little mass near the boundary.

DerivationWhat a margin buys
  1. R(g^)−R∗=E[2∣η−12∣ 1{g^≠g∗}]≤2ε  P(0<∣η(x)−12∣≤ε)R(\hat g)-R^*=\E\Big[2\big|\eta-\tfrac12\big|\,\mathbf 1\{\hat g\ne g^*\}\Big]\le2\varepsilon\;P\Big(0<\big|\eta(\mathbf x)-\tfrac12\big|\le\varepsilon\Big)

    Suppose ∣η^−η∣≤ε\abs{\hat\eta-\eta}\le\varepsilon everywhere. By the first step of the proof above, a mistake at x\mathbf x forces ∣η(x)−1/2∣≤ε\abs{\eta(\mathbf x)-1/2}\le\varepsilon, and points with η=1/2\eta=1/2 cost nothing:

  2. R(g^)−R∗≤2C ε1+αR(\hat g)-R^*\le2C\,\varepsilon^{1+\alpha}

    Apply the margin condition with t=εt=\varepsilon. The general bound is linear in ε\varepsilon; with the margin condition the exponent becomes 1+α1+\alpha:

  3. Combining margin conditions with smoothness of η\eta, Audibert and Tsybakov (2007) showed that plug-in classifiers can attain fast rates, faster than n−1/2n^{-1/2}, and in some regimes "super-fast" rates, faster than n−1n^{-1}, with matching minimax lower bounds. This refuted two conjectures of the time: that n−1n^{-1} is the best achievable rate, and that plug-in classifiers generally converge more slowly than classifiers based on empirical risk minimization.

Think first η(x)\eta(\mathbf x) never lies in (0.4,0.6)(0.4,0.6), and your estimate satisfies ∣η^−η∣≤0.05\abs{\hat\eta-\eta}\le0.05 everywhere. What is the excess risk of the plug-in classifier? Commit to a number before revealing.

Exactly zero. Where η≥0.6\eta\ge0.6, η^≥0.55>1/2\hat\eta\ge0.55>1/2; where η≤0.4\eta\le0.4, η^≤0.45<1/2\hat\eta\le0.45<1/2. The plug-in rule agrees with g∗g^* everywhere, so the identity gives 00. The general bound 2 E∣η^−η∣≤0.12\,\E\abs{\hat\eta-\eta}\le0.1 is valid but loose: this is the margin condition at its extreme, with no mass at all within 0.10.1 of the boundary.

Consistency without rates

With kk fixed the rule is not consistent in general. Cover and Hart (1967) showed that, under mild conditions, the 1-nearest-neighbor risk tends to a limit RNNR_{\mathrm{NN}} with R∗≤RNN≤2R∗(1−R∗)R^*\le R_{\mathrm{NN}}\le2R^*(1-R^*) for two classes: within a factor of two of the Bayes error, but not at it. The Convergence lesson Consistency of Nearest Neighbors proves both results.

Read the two theorems together. Some rules converge to the Bayes error for every distribution, yet for any rule and any rate, however slow, some distribution makes it converge more slowly still, even with noiseless labels. A rate is a statement about a class of distributions: smooth η\eta, a margin condition, or g∗g^* inside a class of finite VC dimension. This is the asymptotic twin of the theorem in the Convergence lesson No Free Lunch & Inductive Bias.

In the terms of The Learning Problem, universal consistency forces a trade. The class must grow with nn so that the approximation error vanishes for every PP, but slowly enough that the estimation error vanishes too. The kk-NN rule does this through kk; empirical risk minimization does it over a growing sequence of classes, the idea behind sieves and structural risk minimization (Shalev-Shwartz & Ben-David, 2014, chapter 7).

Think first A colleague's new classifier comes with a proof of universal consistency. What does that tell you about its error with n=10,000n=10{,}000 examples on your problem?

Nothing quantitative. Universal consistency is a limit statement, and by Devroye's theorem some distributions make any rule converge arbitrarily slowly. To predict the error at a given nn you need either a rate under assumptions you believe hold, or, more practically, an honest held-out estimate.

Surrogates that lead to Bayes

Now let labels be y∈{−1,+1}y\in\{-1,+1\}, let f:X→Rf:\mathcal X\to\R be a score with classifier sign⁡f\sign f, and let φ\varphi be a surrogate loss of the margin yf(x)yf(\mathbf x), with φ\varphi-risk Rφ(f)=E φ(yf(x))R_\varphi(f)=\E\,\varphi(yf(\mathbf x)) and Rφ∗=inf⁡fRφ(f)R_\varphi^*=\inf_fR_\varphi(f) over all measurable ff. Everything reduces to a single point x\mathbf x, where η=P(y=1∣x)\eta=P(y=1\mid\mathbf x) and the score is one number α\alpha:

Cη(α)=η φ(α)+(1−η) φ(−α),H(η)=inf⁡α∈RCη(α),H−(η)=inf⁡α: α(2η−1)≤0Cη(α).C_\eta(\alpha)=\eta\,\varphi(\alpha)+(1-\eta)\,\varphi(-\alpha),\qquad H(\eta)=\inf_{\alpha\in\R}C_\eta(\alpha),\qquad H^-(\eta)=\inf_{\alpha:\,\alpha(2\eta-1)\le0}C_\eta(\alpha).

H−H^- is the best conditional φ\varphi-risk available to a score with the wrong sign, or zero.

Lossφ(α)\varphi(\alpha)H(η)H(\eta)ψ(θ)\psi(\theta)
Hingemax⁡(0,1−α)\max(0,1-\alpha)2min⁡(η,1−η)2\min(\eta,1-\eta)∣θ∣\abs{\theta}
Squared(1−α)2(1-\alpha)^24η(1−η)4\eta(1-\eta)θ2\theta^2
Exponentiale−αe^{-\alpha}2η(1−η)2\sqrt{\eta(1-\eta)}1−1−θ21-\sqrt{1-\theta^2}
Logisticln⁡(1+e−α)\ln(1+e^{-\alpha})−ηln⁡η−(1−η)ln⁡(1−η)-\eta\ln\eta-(1-\eta)\ln(1-\eta)12[(1+θ)ln⁡(1+θ)+(1−θ)ln⁡(1−θ)]\tfrac12\big[(1+\theta)\ln(1+\theta)+(1-\theta)\ln(1-\theta)\big]
Perceptronmax⁡(0,−α)\max(0,-\alpha)0000: not calibrated
The optimal score at x\mathbf x is sign⁡(2η−1)\sign(2\eta-1) for the hinge loss, 2η−12\eta-1 for the squared loss, 12ln⁡η1−η\tfrac12\ln\frac{\eta}{1-\eta} for the exponential loss and ln⁡η1−η\ln\frac{\eta}{1-\eta} for the logistic loss. The last three can be inverted to recover η\eta; the hinge loss recovers the Bayes decision but not the probability, which is why SVM scores must be recalibrated before they are read as probabilities.
DerivationFrom surrogate excess risk to 0–1 excess risk
  1. R(sign⁡f)−R∗≤Rhinge(f)−Rhinge∗R(\sign f)-R^*\le R_{\text{hinge}}(f)-R^*_{\text{hinge}}

    For the hinge loss ψ(θ)=θ\psi(\theta)=\theta on [0,1][0,1], so the comparison is linear:

  2. R(sign⁡f)−R∗≤2(Rφ(f)−Rφ∗)R(\sign f)-R^*\le\sqrt{2\big(R_\varphi(f)-R_\varphi^*\big)}

    For the logistic loss, (1+θ)ln⁡(1+θ)+(1−θ)ln⁡(1−θ)=θ2+θ4/6+θ6/15+⋯≥θ2(1+\theta)\ln(1+\theta)+(1-\theta)\ln(1-\theta)=\theta^2+\theta^4/6+\theta^6/15+\cdots\ge\theta^2, so ψ(θ)≥θ2/2\psi(\theta)\ge\theta^2/2; for the exponential loss, 1−1−θ2≥θ2/21-\sqrt{1-\theta^2}\ge\theta^2/2 as well. Either way:

  3. So any procedure that drives the surrogate excess risk to zero is consistent for the 0–1 loss. This is how consistency was established for regularized kernel classifiers such as SVMs (Steinwart, 2005) and for regularized boosting (Lugosi & Vayatis, 2004; Zhang, 2004). The square root costs rate: a surrogate excess risk of order 1/n1/n guarantees only order 1/n1/\sqrt n for the 0–1 loss unless a low-noise condition sharpens the comparison, which Bartlett, Jordan and McAuliffe also quantify.

Check your understanding

Which of these convex losses of the margin is not classification-calibrated?

  1. Hinge, max⁡(0,1−α)\max(0,1-\alpha)
  2. Exponential, e−αe^{-\alpha}
  3. Perceptron, max⁡(0,−α)\max(0,-\alpha)
  4. Logistic, ln⁡(1+e−α)\ln(1+e^{-\alpha})
Show the answer

C. Perceptron, max⁡(0,−α)\max(0,-\alpha)

The perceptron loss has a kink at 00 (slopes −1-1 and 00), so it is not differentiable there and the criterion fails. Directly: the score f≡0f\equiv0 has zero φ\varphi-risk under every distribution, so minimizing this risk says nothing about the sign. The perceptron algorithm still works on separable data because it stops at a separator, not because of calibration.

Key takeaways

  • R(g)−R∗=E[∣2η−1∣ 1{g≠g∗}]R(g)-R^*=\E\big[\abs{2\eta-1}\,\mathbf 1\{g\ne g^*\}\big]: the Bayes classifier 1{η>1/2}\mathbf 1\{\eta>1/2\} is optimal, R∗=Emin⁡(η,1−η)R^*=\E\min(\eta,1-\eta), and mistakes where η\eta is near 1/21/2 are nearly free.
  • A plug-in rule loses at most 2 E∣η^−η∣2\,\E\abs{\hat\eta-\eta}; under a margin condition with exponent α\alpha, a uniform estimation error ε\varepsilon costs only order ε1+α\varepsilon^{1+\alpha}.
  • Universally consistent rules exist (kk-NN with k→∞k\to\infty and k/n→0k/n\to0: Stone, 1977), but no rate of convergence holds for every distribution (Devroye, 1982). Every rate is bought with assumptions.
  • A surrogate is classification-calibrated when wrong signs cost strictly more conditional risk; a convex φ\varphi is calibrated if and only if φ′(0)\varphi'(0) exists and is negative. Then ψ(R(sign⁡f)−R∗)≤Rφ(f)−Rφ∗\psi(R(\sign f)-R^*)\le R_\varphi(f)-R_\varphi^*, with ψ(θ)=∣θ∣\psi(\theta)=\abs\theta for the hinge loss and ψ(θ)≥θ2/2\psi(\theta)\ge\theta^2/2 for the logistic and exponential losses.

Check yourself

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

Question 1

At a point with η(x)=0.8\eta(\mathbf x)=0.8, a classifier predicts 00. How much does this point contribute to R(g)−R∗R(g)-R^*, per unit of probability mass?

  1. 0.20.2
  2. 0.60.6
  3. 0.80.8
  4. 1.01.0
Show the answer

B. 0.60.6

The weight is ∣2η−1∣=0.6\abs{2\eta-1}=0.6: the classifier errs with conditional probability 0.80.8 where the Bayes classifier errs with 0.20.2.

Question 2

An estimate satisfies E∣η^(x)−η(x)∣≤0.02\E\abs{\hat\eta(\mathbf x)-\eta(\mathbf x)}\le0.02. What does the plug-in bound guarantee about the excess risk of 1{η^>1/2}\mathbf 1\{\hat\eta>1/2\}?

  1. At most 0.010.01
  2. At most 0.020.02
  3. At most 0.040.04
  4. At most 0.20.2
Show the answer

C. At most 0.040.04

R(g^)−R∗≤2 E∣η^−η∣≤0.04R(\hat g)-R^*\le2\,\E\abs{\hat\eta-\eta}\le0.04. The factor 22 comes from ∣2η−1∣=2∣η−1/2∣\abs{2\eta-1}=2\abs{\eta-1/2}.

Question 3

Which choice of k=knk=k_n makes the kk-nearest-neighbor rule universally consistent?

  1. k=1k=1 for every nn
  2. k=7k=7 for every nn
  3. k=⌊n/2⌋k=\lfloor n/2\rfloor
  4. k=⌊n⌋k=\lfloor\sqrt n\rfloor
Show the answer

D. k=⌊n⌋k=\lfloor\sqrt n\rfloor

Stone's conditions are k→∞k\to\infty and k/n→0k/n\to0; k=nk=\sqrt n satisfies both. Growing kk averages away the noise, and k/n→0k/n\to0 keeps the neighbors local.

Question 4

An SVM's excess hinge risk is 0.050.05. What does the comparison inequality guarantee about its excess 0–1 risk?

  1. At most 0.050.05
  2. At most 0.10.1
  3. At most 2×0.05≈0.32\sqrt{2\times0.05}\approx0.32
  4. At most 0.0250.025
Show the answer

A. At most 0.050.05

For the hinge loss ψ(θ)=∣θ∣\psi(\theta)=\abs\theta, so R(sign⁡f)−R∗≤Rhinge(f)−Rhinge∗=0.05R(\sign f)-R^*\le R_{\text{hinge}}(f)-R^*_{\text{hinge}}=0.05.

Further reading

  • L. Devroye, L. Györfi & G. Lugosi, A Probabilistic Theory of Pattern Recognition (Springer, 1996).
  • C. J. Stone, "Consistent nonparametric regression," Annals of Statistics 5(4), 595–620 (1977).
  • L. Devroye, "Any discrimination rule can have an arbitrarily bad probability of error for finite sample size," IEEE Transactions on Pattern Analysis and Machine Intelligence PAMI-4(2), 154–157 (1982).
  • P. L. Bartlett, M. I. Jordan & J. D. McAuliffe, "Convexity, classification, and risk bounds," Journal of the American Statistical Association 101(473), 138–156 (2006).
  • J.-Y. Audibert & A. B. Tsybakov, "Fast learning rates for plug-in classifiers," Annals of Statistics 35(2), 608–633 (2007).