Skip to content

Read the question, then do the math

A question can look unfamiliar because several familiar operations have been packed into one line. Start by identifying the objects, the assumptions, and the requested output. Try each problem before opening its walkthrough.

Question. Let Y=X2+εY=X^2+\varepsilon, where εX\varepsilon\perp X and εUnif[1,1]\varepsilon\sim\operatorname{Unif}[-1,1]. For h(x)=x3h(x)=x^3, compute

E[(Yh(X))2X=1/2].\mathbb E[(Y-h(X))^2\mid X=1/2].

You are being asked for one number. The condition after the vertical bar fixes XX. The outer expectation averages the squared error over the remaining randomness in YY.

1. Decode what you were given
  • εX\varepsilon\perp X: epsilon is independent of X. Fixing X does not change its distribution.
  • εUnif[1,1]\varepsilon\sim\operatorname{Unif}[-1,1]: the noise is uniform on that interval. Its mean is zero and variance is 1/31/3.
  • hh: the prediction rule you must evaluate, not the true conditional mean.
  • E[X=1/2]\mathbb E[\cdot\mid X=1/2]: set X to one-half, then average over the noise.
2. Substitute before expanding Y=1/4+ε,h(1/2)=1/8.Y=1/4+\varepsilon,\qquad h(1/2)=1/8.

So the random error is 1/8+ε1/8+\varepsilon. The question has become: what is the average square of one-eighth plus this noise?

3. Square and average E[(1/8+ε)2]=1/64+(1/4)E[ε]+E[ε2]=1/64+0+1/3=67/192.\begin{aligned} \mathbb E[(1/8+\varepsilon)^2] &=1/64+(1/4)\mathbb E[\varepsilon]+\mathbb E[\varepsilon^2]\\ &=1/64+0+1/3=67/192. \end{aligned}

Why does E[ε2]=1/3\mathbb E[\varepsilon^2]=1/3? Variance is E[ε2](E[ε])2\mathbb E[\varepsilon^2]-(\mathbb E[\varepsilon])^2, and the mean is zero.

Check the answer: it is above 1/31/3, the expected error of guessing the conditional mean. The extra 1/641/64 is the squared miss of our rival prediction.

Question. For observations y1=0y_1=0, y2=0y_2=0, and y3=9y_3=9, find

c=arg mincR13i=13(yic)2.c^*=\operatorname*{arg\,min}_{c\in\mathbb R}\frac13\sum_{i=1}^{3}(y_i-c)^2.
Decode the question

cRc\in\mathbb R means you may choose any real number. The sum scores that choice on the three observations. Argmin asks for the winning choice of c, not its score. The star labels the optimal choice; it is not multiplication.

Solve and distinguish the two answers

The mean minimizes squared error, so c=(0+0+9)/3=3c^*=(0+0+9)/3=3.

The minimum score is (9+9+36)/3=18(9+9+36)/3=18. An answer of 18 would answer “what is the minimum?” rather than “which c achieves it?”

Change the loss to yic\lvert y_i-c\rvert and the optimal choice becomes the median, 0. Always read the scoring rule.

Question. At x0x_0, f(x0)=4f(x_0)=4, ED[f^D(x0)]=5\mathbb E_D[\hat f_D(x_0)]=5, VarD(f^D(x0))=2\operatorname{Var}_D(\hat f_D(x_0))=2, and Var(Y0X0=x0)=3\operatorname{Var}(Y_0\mid X_0=x_0)=3. Assume independent training and future examples. Find the expected squared prediction error at x0x_0.

What is random this time?

The input x0x_0 is fixed. The dataset subscript D means we repeatedly draw training datasets, fit a model to each, and inspect its prediction at x0x_0. There is also fresh output noise. The variance of the predictions (2) and the variance of the outputs around f (3) refer to different experiments.

Work the three terms

Bias is 54=15-4=1. Squared bias is 1. Add prediction variance and noise variance: 1+2+3=61+2+3=6.

This is a theoretical average over datasets and fresh outputs. It does not say that the MSE on your next finite test set will equal 6.

Question. Let x=(2,5)x=(2,5), β=(3,1)\beta=(3,-1), and β0=4\beta_0=4. Evaluate β0+βx\beta_0+\beta^\top x.

Translate and calculate

The transpose symbol \top turns the coefficient column into a row so the product is a dot product. Multiply corresponding entries and add:

β0+βx=4+(32)+(15)=5.\beta_0+\beta^\top x=4+(3\cdot2)+(-1\cdot5)=5.

There are two features in this one example. These are not two training rows.

Question. Let Y=2X+εY=2X+\varepsilon, with finite means and E[ε]=0\mathbb E[\varepsilon]=0. Must E[YX]=2X\mathbb E[Y\mid X]=2X?

Separate the overall average from the conditional average

Conditioning gives

E[YX]=2X+E[εX].\mathbb E[Y\mid X]=2X+\mathbb E[\varepsilon\mid X].

The given overall average does not determine the average within each input group. For example, let X be equally likely to be −1 or 1, and let ε=X\varepsilon=X. The noise has overall mean zero, but Y=3XY=3X, so E[YX]=3X\mathbb E[Y\mid X]=3X.

We need zero conditional mean, E[εX]=0\mathbb E[\varepsilon\mid X]=0. Independence of X and ε together with zero overall noise mean would also be sufficient. Zero overall mean alone is not.

Mixed practice changes the numbers and the kind of question. Start without a hint; if needed, reveal a translation before the worked answer.

Definition

Read the full glossary entry →