Interactive explainer
Regression and overfitting – interactive calculator
A curve can fit familiar observations extremely well and predict new ones poorly. Compare polynomial degrees on the same training and holdout data, and see when additional flexibility becomes harmful.
Compare a polynomial curve’s training fit with its performance on 80 independent holdout observations. All observations are synthetic. The true relationship combines a sine curve with a linear component, plus adjustable noise. Calculations run locally in your browser and do not require your own data.
Regression and overfitting – interactive calculator
Only training observations determine the fitted curve. Degrees one to twelve change flexibility; the holdout remains fixed when training size changes.
Three experiments
- Increase flexibility. Start at degree one and increase it gradually. Compare training and holdout error. Look for a range where the training fit improves but predictions for the comparison observations no longer benefit. Inspect the curve as well as the numbers.
- Add more noise. Hold degree and sample size fixed, then increase noise. The same random draws are scaled more strongly. Watch whether the curve follows individual deviations and swings between observed points.
- Use more data. Compare 16 and 60 training observations at a high degree. Additional observations extend the same sample; the 80 holdout observations stay unchanged. Reset everything afterwards.
What the errors tell you
Mean squared error gives large deviations particularly strong weight. The table reports it for all twelve degrees. Numerically stable computation does not prevent overfitting; large excursions can be a correctly calculated result. Repeatedly using the holdout to select the best degree means that fresh test data will be needed later. The regression and overfitting article explains data separation, assumptions and common mistaken conclusions.