Visualizing Overfitting and Regularization

Interactive demo on Overfitting and Regularization

Train Error:
Test Error:

How to Use

  • Adjust Model Complexity to see how higher-degree polynomials fit the data (and noise)
  • Increase Regularization to smooth the fit and reduce overfitting
  • Click Reset Data to randomize the dataset
  • Watch train/test errors update live

What You’re Seeing

  • Blue circles: Training data points (what the model learns from)
  • Red X markers: Test data points (unseen data used to evaluate generalization)
  • Orange curve: Model fit curve
  • Train/Test Error: Root mean squared error for each set

Key Observations

  • High complexity fits noise (overfitting: low train error, high test error)
  • Regularization smooths the fit, reducing overfitting
  • Underfitting occurs at low complexity (high errors)
  • The best fit balances bias and variance

Try different settings and see the bias-variance tradeoff in action!