04 / Machine learning
Fit the signal.
Not the noise.
A more flexible model can follow the training data closely. That does not guarantee good predictions on data it has never seen.
Polynomial regression
20 training points · 200 test pointsA signal we can inspect.
The observations come from a known curve plus independent Gaussian noise. Training inputs are evenly spaced; held-out inputs are newly sampled uniformly from the same interval.
A polynomial model is fitted only to the 20 training observations. Its flexibility is controlled by the degree :
The are Legendre polynomials. They span the same degree- polynomial family as ordinary powers, with better numerical behavior on this interval.
Regularization penalizes nonconstant coefficients. The fit minimizes:
The intercept is not penalized. The penalty depends on this choice of basis.
Watch the error you did not fit.
- Set regularization to zero and increase the degree. Training error cannot increase for these nested least-squares models, apart from numerical rounding.
- Compare the held-out error. Extra flexibility may fit noise and hurt prediction.
- Add regularization or try a new sample. Which patterns survive?
Held-out MSE uses 200 observations excluded from fitting. The noise variance is the irreducible error in expectation for new noisy responses. A finite-sample MSE can fall below it.
This is a demonstration of generalization, not a measured bias–variance decomposition. A single test split can be lucky or unlucky.
Repeatedly choosing settings from test error turns the test set into validation data. A real workflow keeps a final, untouched test set. All data here are synthetic and generated locally.