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

02Setting and notation

2.1The data-generating process

We observe input–output pairs (x,y), with x a vector of features and y a real number. We assume

y = f(x) + \varepsilon,\qquad \E[\varepsilon]=0,\qquad \Var(\varepsilon)=\sigma^2, \tag{2}

where f is a fixed but unknown function and the noise \varepsilon is independent of everything else. The noise collects everything about y that x cannot explain: measurement error, influences we did not record, genuine randomness. Since \E[y\mid x]=f(x), the function f is the best possible predictor under squared loss, and even it has expected squared error \E[(y-f(x))^2]=\sigma^2 at every x. No model can do better than this noise floor.

2.2Training sets are random, so models are random

A training set \D=\{(x_1,y_1),\dots,(x_n,y_n)\} is a random sample from the population. A learning procedure, which includes the model family, the fitting algorithm and every hyperparameter, maps \D to a fitted function \fhat(\,\cdot\,;\D). For example, “fit a polynomial of degree 4 by least squares” maps fifteen points to one particular polynomial.

The key observation is that because \D is random, the prediction \fhat(x;\D) at a fixed input x is itself a random variable. A useful thought experiment, used in many lecture notes (e.g. Weinberger, 2018), is to imagine many parallel universes. In each one, we draw a fresh training set of the same size from the same population, run the same learning procedure, and record its prediction at x. The predictions differ from universe to universe. Their average tells us whether the procedure is right on target; their spread tells us how much it depends on the luck of the draw.

2.3Expected test error, bias and variance

We judge a prediction by squared loss, (y-\fhat(x))^2, on a new observation y=f(x)+\varepsilon at input x, independent of the training data. Averaging over both sources of randomness, the training set and the new noise, gives the expected test error at x,

\mathrm{Err}(x) \;=\; \E_{\D,\varepsilon}\!\left[\big(y-\fhat(x;\D)\big)^2\right]. \tag{3}

Definition 1 (Average model, bias and variance). At a fixed input x, the average model, the bias and the variance of a learning procedure are

\fbar(x)=\E_{\D}\!\left[\fhat(x;\D)\right],\qquad \Bias(x)=\fbar(x)-f(x),\qquad \Var(x)=\E_{\D}\!\left[\big(\fhat(x;\D)-\fbar(x)\big)^2\right]. \tag{4}

The bias is the systematic error of the procedure: where it lands on average, relative to the truth. The variance is the expected squared deviation of a single fitted model from that average. Both are numbers attached to each input x; we usually summarize them by averaging over the inputs we care about.

2.4Three remarks that prevent confusion

  1. The average model is not a model you can train. \fbar averages over infinitely many training sets that we never have. It is a theoretical device, although we can approximate it in simulations (Section 6).
  2. Bias and variance belong to the procedure, not to one fitted model. They depend on the model family, the algorithm, the hyperparameters and the sample size n. A single fitted model has an error; it does not “have” a variance. Saying “this model has high variance” is shorthand for “this procedure, at this sample size, would give a very different model with a different sample.”
  3. Fixed or random inputs. In some analyses the training inputs x_1,\dots,x_n are held fixed and only the labels are random (“fixed design”); in others the inputs are random too. The decomposition holds either way; only the meaning of \E_{\D} changes. Several closed forms in Section 7 use the fixed-design view because it keeps the algebra simple.