Solution 7. Express the prediction error as noise plus the error of the prediction, used as an estimator of the mean function value \({\mu\mathopen{}\left(x\right)\mathclose{}}\):
\[
\begin{aligned}
Y_{*}- {\hat y\mathopen{}\left(x\right)\mathclose{}}
&= \mathopen{}\left(Y_{*}- {\mu\mathopen{}\left(x\right)\mathclose{}}\right)\mathclose{} + \mathopen{}\left({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right)\mathclose{}
&& \text{(add and subtract } {\mu\mathopen{}\left(x\right)\mathclose{}} \text{)} \\
&= \varepsilon+ \mathopen{}\left({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right)\mathclose{}
&& \text{(definition of } Y_{*}\text{)}
\end{aligned}
\]
Square it:
\[
\begin{aligned}
{\mathopen{}\left(Y_{*}- {\hat y\mathopen{}\left(x\right)\mathclose{}}\right)\mathclose{}}^{2}
&= \varepsilon^2
+ 2 \varepsilon\mathopen{}\left({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right)\mathclose{}
+ {\mathopen{}\left({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right)\mathclose{}}^{2}
&& \text{(expand the square of a sum)}
\end{aligned}
\]
Take the expectation of each term in turn, using linearity of expectation to distribute the expectation over the sum.
For the noise term, the variance identity gives \(\sigma^2= {\mathbb{E}\mathopen{}\left[\varepsilon^2\right]\mathclose{}} - {\mathopen{}\left({\mathbb{E}\mathopen{}\left[\varepsilon\right]\mathclose{}}\right)\mathclose{}}^{2}\):
\[
\begin{aligned}
{\mathbb{E}\mathopen{}\left[\varepsilon^2\right]\mathclose{}}
&= \sigma^2+ {\mathopen{}\left({\mathbb{E}\mathopen{}\left[\varepsilon\right]\mathclose{}}\right)\mathclose{}}^{2}
&& \text{(variance identity)} \\
&= \sigma^2+ 0^2
&& \text{(the noise has population mean } 0 \text{)} \\
&= \sigma^2
&& \text{(} 0^2 = 0 \text{, and } \sigma^2+ 0 = \sigma^2\text{)}
\end{aligned}
\]
For the cross term, \(\varepsilon= Y_{*}- {\mu\mathopen{}\left(x\right)\mathclose{}}\) shifts \(Y_{*}\) by a constant, and \(Y_{*}\) is independent of \(\mathcal{D}_{\text{train}}\), so \(\varepsilon\) is independent of \(\mathcal{D}_{\text{train}}\), and hence of \({\hat y\mathopen{}\left(x\right)\mathclose{}}\) and of \({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\). The expectation of a product of independent random variables is the product of their expectations:
\[
\begin{aligned}
{\mathbb{E}\mathopen{}\left[2 \varepsilon\mathopen{}\left({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right)\mathclose{}\right]\mathclose{}}
&= 2 {\mathbb{E}\mathopen{}\left[\varepsilon\mathopen{}\left({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right)\mathclose{}\right]\mathclose{}}
&& \text{(constant factor 2)} \\
&= 2 {\mathbb{E}\mathopen{}\left[\varepsilon\right]\mathclose{}} {\mathbb{E}\mathopen{}\left[{\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right]\mathclose{}}
&& \text{(independence)} \\
&= 2 \cdot 0 \cdot {\mathbb{E}\mathopen{}\left[{\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right]\mathclose{}}
&& \text{(the noise has population mean } 0 \text{)} \\
&= 0
&& \text{(zero times a number)}
\end{aligned}
\]
Adding the three expectations,
\[
{\mathbb{E}\mathopen{}\left[{\mathopen{}\left(Y_{*}- {\hat y\mathopen{}\left(x\right)\mathclose{}}\right)\mathclose{}}^{2}\right]\mathclose{}}
= \sigma^2+ {\mathbb{E}\mathopen{}\left[{\mathopen{}\left({\mu\mathopen{}\left(x\right)\mathclose{}} - {{\hat{\mu}\mathopen{}\left(x\right)\mathclose{}}}\right)\mathclose{}}^{2}\right]\mathclose{}}.
\tag{36}\]
The noise has population mean \(0\) by Theorem 1, so the algebra used only one hypothesis about the new observation: it is independent of the training set. Independence holds for a fresh observation, and it fails for an observation the procedure was trained on, whose noise helped determine the prediction. It also fails when the new observation depends on the training data (for example, a later time in the same series), or when the same test set was used to choose the procedure.
The algebra did not use that the new pair has the same population distribution as the training data. Suppose the new pair came from a population whose mean function differed from the training population’s. Then Equation 36 would still hold, with the new population’s mean function and noise variance. Its estimation-error term would include the bias from that difference. So it would no longer measure how well the procedure estimates the training population’s mean function.