Why is the predictor that minimises the expected squared loss the conditional mean E[Y∣X=x], and why is the classifier that minimises the expected 0-1 loss arg⁡max⁡kP(Y=k∣X=x)?

Foundations, Statistical decision theory
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can minimise an expected loss one input x at a time, and know which “ideal” model each loss is aiming for.

Key idea

Write the risk as R(f)=EX[E[ℓ(f(X),Y)∣X]] and minimise the inner part separately for each x. For squared loss the inner part is a parabola in the prediction c, lowest at c=E[Y∣x]. For 0-1 loss, predicting class k costs 1−P(Y=k∣x).

Steps

  1. Use the tower rule E[Z]=EX[E[Z∣X]] to write R(f)=EX[E[ℓ(f(X),Y)∣X]]. The value f(x) can be chosen separately for each x, so it is enough to make the inner term as small as possible at every x.
  2. Squared loss. Let m(x)=E[Y∣x] and add and subtract it: E[(Y−c)2∣x]=E[(Y−m)2∣x]+(m−c)2. The cross term 2(m−c) E[Y−m∣x] is zero, because Y−m has mean zero given x.
  3. The first term does not depend on c, and the second is smallest (zero) at c=m(x). So f∗(x)=E[Y∣x]. What is left, Var⁡(Y∣x), is noise that no model can remove.
  4. 0-1 loss. This loss is 1 for a wrong class and 0 for the right one. Predicting class k gives expected loss E[1{Y≠k}∣x]=1−P(Y=k∣x), which is smallest for the class with the largest posterior probability. So f∗(x)=arg⁡max⁡kP(Y=k∣x).
  5. Name the result. This is the Bayes classifier, and its error R∗=EX[1−max⁡kP(Y=k∣X)] is the Bayes error. No classifier can do better.
  6. Add a remark. The same argument with absolute loss ∣Y−c∣ gives the conditional median. The loss you train with decides what your model is estimating.

Common mistakes

How long your answer should be

Half a page; about 4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Foundations: For a single weight w and a number z, solve min⁡w12(w−z)2+λ∣w∣ and min⁡w12(w−z)2+λ2w2. Why does this show that L1 regularisation gives sparse solutions and L2 does not?
Next in Foundations: Consider a d-dimensional unit-radius hypersphere inscribed inside the hypercube [−1,1]d. Using the hypersphere volume Vd(r)=πd/2Γ(d/2+1)rd (where Γ(k+1)=k! for an integer k), what fraction of the hypercube's volume does the sphere occupy for d=2, 4 and 10, and what does this imply about uniformly sampled points in high dimensions?