MoonSay /Tutorials/Machine Learning Interview #2
Contents
  1. 01Introduction
  2. 02Setting and notation
  3. 03Intuition
  4. 04The decomposition and its proof
  5. 05A warm-up you can do by hand
  6. 06The experiment
  7. 07Models where every term has a formula
  8. 08Diagnosing bias and variance in practice
  9. 09Fixing high bias and high variance
  10. 10Beyond the classical picture
  11. 11Interview questions and model answers
  12. 12Summary
  13. References

05A warm-up you can do by hand: estimating a mean

The tradeoff already appears in the simplest estimation problem there is. Let z_1,\dots,z_n be independent observations with unknown mean \mu and variance \sigma^2. The sample mean \bar z is unbiased with \Var(\bar z)=\sigma^2/n. Now consider the shrunken estimator

\hat\mu_c=c\,\bar z,\qquad 0\le c\le 1,

which pulls the sample mean toward zero (the sample mean itself is c=1). For an estimator of a number the decomposition reads \MSE=\Bias^2+\Var, with no noise term because we are estimating \mu itself rather than a noisy observation. Using \E[c\,\bar z]=c\mu and \Var(c\,\bar z)=c^2\Var(\bar z),

\Bias(\hat\mu_c)=(c-1)\mu,\qquad \Var(\hat\mu_c)=c^2\frac{\sigma^2}{n},\qquad \MSE(c)=(1-c)^2\mu^2+c^2\,\frac{\sigma^2}{n}. \tag{7}

Shrinking (c<1) introduces bias but removes variance. \MSE(c) is a convex quadratic in c; setting its derivative to zero,

\MSE'(c)=-2(1-c)\mu^2+2c\,\frac{\sigma^2}{n}=0 \quad\Longrightarrow\quad c^\star=\frac{\mu^2}{\mu^2+\sigma^2/n},

and substituting back,

\MSE(c^\star)=\frac{\mu^2\,\sigma^2/n}{\mu^2+\sigma^2/n}\;<\;\frac{\sigma^2}{n}=\MSE(1). \tag{8}

So some shrinkage always helps, and it helps most when the signal \mu^2 is small relative to the variance \sigma^2/n of the sample mean: few observations, noisy data, or a true value near the point we shrink toward.

Worked example 1. Take \mu=1, \sigma=2 and n=10, so \sigma^2/n=0.4. The sample mean has \MSE=0.400, all of it variance. The optimal shrinkage is c^\star=1/1.4=0.714, with bias -0.286, squared bias 0.082, and variance 0.714^2\times0.4=0.204, so \MSE=0.286, a reduction of about 29%. A simulation with 200,000 repetitions gives 0.399 for the sample mean and 0.285 for the shrunken estimator. Figure 3 plots the three curves.

Bias^2, variance and MSE of the shrunken mean c\,\bar z for \mu=1, \sigma^2/n=0.4 (Example 1). Curves drawn from (7).
Figure 3. Bias^2, variance and MSE of the shrunken mean c\,\bar z for \mu=1, \sigma^2/n=0.4 (Example 1). Curves drawn from (7).
Try itShrink the sample mean

The estimator c\,\bar z multiplies the sample mean by a factor c. Left: its sampling distribution (teal) against that of the plain sample mean (dashed); the gap between the purple line and the gold truth is the bias. Right: the three terms of \MSE(c)=(1-c)^2\mu^2+c^2\sigma^2/n, with the best c^\star=\mu^2/(\mu^2+\sigma^2/n) in gold.

The catch, and why it matters. The optimal c^\star depends on the unknown \mu, so we cannot compute it exactly. In practice the amount of shrinkage is a hyperparameter chosen from data, exactly like a regularization strength. Remarkably, for Gaussian data in three or more dimensions there is a data-driven shrinkage, the James–Stein estimator, whose total MSE is lower than that of the sample means for every value of the true means (Stein, 1956; James and Stein, 1961). The “Bayesian average” used to rank items with few ratings (Section 3) is the same idea: shrink noisy averages toward a common value, more strongly when they rest on fewer observations.

A real example: batting averages. Efron and Morris (1977) gave the best-known demonstration with real data. They took 18 major-league baseball players’ batting averages after their first 45 at-bats of the 1970 season and asked which estimate would better predict each player’s average over the rest of the season: his own early average, or that average shrunk toward the group mean of 0.265. The James–Stein estimator shrank every player about 79% of the way to the group mean, keeping only a fraction c=0.212 of each deviation: Roberto Clemente’s early 0.400 became 0.265+0.212\times(0.400-0.265)\approx0.294. The shrunken estimates were closer to the season averages for 16 of the 18 players. Each player’s 45 at-bats were simply too few: his early average had low bias but high variance, and borrowing strength from the other players traded a little bias for a large reduction in variance.