Overfitting Sandbox illustration

Overfitting Sandbox

Fit polynomials of degree 0 to 15 to noisy samples from a hidden function and watch underfitting turn into overfitting. Pick the true curve (sine, step or cubic), the noise level and the sample size; the sandbox splits the data 70/30 into filled training points and hollow test points, fits the chosen degree by least squares on Chebyshev-scaled features, and draws the fitted curve over the dashed truth. Drag the degree up and watch the curve chase every training point while swinging wildly between them; press Sweep degrees and the lower chart traces train and test error across all degrees — the classic U-shaped test curve whose minimum marks the sweet spot. A verdict line calls out underfit, good fit or overfit.

Runs 100% in your browser — models are trained and computed locally on your device.

Notes

  • Training error falls (weakly) as degree grows, but test error is U-shaped — the bias–variance tradeoff in one chart.
  • Test MSE can never reliably beat the noise floor σ²: once the true curve is captured, what remains is irreducible noise.
  • Fitting uses a Chebyshev polynomial basis on [−1, 1]; raw powers x¹⁵ would make the normal equations catastrophically ill-conditioned.
  • A degree-n polynomial can interpolate n + 1 training points exactly — high degrees will happily fit pure noise.
  • Runs 100% in your browser — models are trained and computed locally on your device.