Every predictive model in data science is a compromise between fitting the data you have and generalizing to data you haven't seen. This simulation generates a synthetic dataset — points scattered in 3D around a hidden "true" surface with added noise — then fits a polynomial regression surface to a training subset using least-squares. Watching the fitted surface change as you turn the complexity dial up or down makes underfitting and overfitting tangible instead of abstract.
Practitioners guard against overfitting with techniques like cross-validation, regularization (ridge/lasso) and simply collecting more data — all of which, in effect, trade a little training accuracy for a model that generalizes better.
A 3D scatter of noisy data points around a hidden true surface, with a polynomial regression fit you can push from too-simple to too-flexible, watching training and test error diverge as it overfits.
The bias–variance tradeoff at the heart of predictive modeling: low-degree fits underfit real structure, high-degree fits chase noise, and only a middle ground generalizes well from training data to unseen test data.
Pick a true pattern, then drag the complexity slider up and down while watching the fitted surface reshape and the train/test RMSE readouts respond. Increase noise or shrink the sample size to see overfitting appear sooner.
The same normal-equation least-squares math used here scales up to the linear and polynomial regression models that power real analytics pipelines — the difference is dimensionality, not the underlying idea.