Section 5.2, pp. 108 to 109, defines generalization through unseen inputs and discusses training and testing under a shared p_data. Independent identically distributed examples connect finite sample averages with population expectations. Independence and a common distribution are separate requirements. Overlapping examples, temporal dependence and a changed deployment distribution require additional treatment. The risk notation below formalizes the source discussion.
R(h)=E_(X,Y)∼p_data[ℓ(h(X),Y)]; R̂_S(h)=(1/m)Σᵢℓ(h(xᵢ),yᵢ); gap=R(ĥ_S)−R̂_S(ĥ_S).
R̂_train(w)=‖X_train w−y_train‖₂²/m_train; R̂_test(w)=‖X_test w−y_test‖₂²/m_test. [5.14 and following text]
For h fixed independently of the training sample, the same sampling mechanism gives E[R̂_train(h)]=E[R̂_test(h)]=R(h). A learned ĥ_S depends on S, changing the relationship to its training examples. If the test set remains independent after selection, E[R̂_test(ĥ_S)|S]=R(ĥ_S). A finite test mean still has sampling error.
The source describes expected test error as at least expected training error after learning. This note retains the empirical risk minimization context. The inequality below holds for exact empirical risk minimization in a fixed hypothesis space. It is not a guarantee for every algorithm or every random split. A regularized solution need not minimize the unpenalized training error.
ĥ_S∈argmin_(h∈H)R̂_S(h) ⇒ E_S R̂_S(ĥ_S) ≤ inf_(h∈H)R(h) ≤ E_S R(ĥ_S).
For each S, the empirical minimum is no greater than the empirical risk of any fixed h. Taking expectation and then the infimum over h proves the first inequality. Population risk is always at least the best risk in the same space, which proves the second. The argument explains why fixing a model before sampling differs from selecting it after sampling.
Exact empirical risk minimization is sufficient rather than necessary. Exact minimization of empirical risk plus a fixed, data independent penalty over the same fixed family also gives expected training error no greater than expected population error. Comparing solutions from independent training samples and taking expectations cancels the penalty terms. The sandwich inequality above concerns unpenalized ERM and does not directly apply to the penalized solution.