06 — Evaluate Your Model

Learning Curves & Overfitting#

DiagnosticsStatistical 1 min read
◆ The PatternTraining vs validation curves — reading the gap to diagnose models

A learning curve plots training and validation scores as data increases. The gap between them tells you everything: large gap = overfitting, both low = underfitting, converging = sweet spot. It also tells you if more data would help.

Gap = Scoretrain − Scoreval
Large gap = overfitting (model memorises)  |  Both low = underfitting (model too simple)
// Interactive — adjust complexity, see the gap
Model complexity50
Diagnosis—
Pattern bridge: The learning curve gap is the visual form of the bias-variance tradeoff. The same tension appears in walk-forward backtesting — overfitting to past market conditions. Guide: Why is my model not generalising?
How to use this in practice
  1. Plot learning curves early in your project — before spending time on feature engineering
  2. Large gap (overfit) → try regularization, dropout, less complex model, or more data
  3. Both scores low (underfit) → try more features, more complex model, or feature engineering
  4. Curves converging but slowly → more data will help — go collect it
  5. Curves flat and apart → more data won't help — simplify the model instead
Common pitfall — early stopping too early: If your validation curve is still improving, you're stopping before convergence. If your training curve keeps rising while validation drops, you've gone past the sweet spot. Use a patience parameter (e.g. 10 epochs with no improvement) to find the right moment.
Experiment — diagnose the learning curve
Diagnosis: Adjust the sliders to see how model complexity, data size, and noise affect the learning curve gap.
→ Balanced setup — moderate gap between train and val scores
When to use this
✓ Use when: You need to decide between getting more data vs. improving the model. Diagnosing overfitting vs underfitting. Justifying compute budget — will more training help? Before deploying to production as a sanity check.
✗ Skip when: You're doing a quick prototype where directional results are enough. Using pre-trained models where the learning dynamics are already well-studied. The dataset is fixed and you can't get more data anyway.
Worked example

A degree-7 polynomial fitted to a noisy sine wave. With 20 points the training error is 0.050 and the validation error 0.155; with 80, 0.079 and 0.102; with 320, 0.094 and 0.095. Training error rises and validation error falls until they meet near the noise level (0.09). A gap that is still closing says more data will help.

Where it misleads
  • Curves from a single split are noisy; average several before reading a trend into them.
  • Learning curves for different models cross: the best model for small data is often not the best for large (Perlich, Provost & Simonoff 2003).
  • A flat validation curve can mean the model is limited, or that the labels are too noisy to learn more from.
In code
rng = np.random.default_rng(3)
f = lambda x: np.sin(3 * x)
x_val = rng.uniform(-1, 1, 2_000); y_val = f(x_val) + rng.normal(0, 0.3, 2_000)
gaps = {}
for n in (20, 80, 320):
    x = rng.uniform(-1, 1, n); y = f(x) + rng.normal(0, 0.3, n)
    c = np.polyfit(x, y, 7)
    train = ((np.polyval(c, x) - y) ** 2).mean(); val = ((np.polyval(c, x_val) - y_val) ** 2).mean()
    gaps[n] = (round(train, 3), round(val, 3))
Python, in your browser — edit the code and run it again

Assumes import numpy as np and import pandas as pd (and SciPy where imported). Each snippet simulates or makes up its own data, as the comments say.

The same idea with a library
# Python — learning curves
from sklearn.model_selection import learning_curve
import matplotlib.pyplot as plt

sizes, train_scores, val_scores = learning_curve(
    model, X, y, cv=5, n_jobs=-1,
    train_sizes=np.linspace(0.1, 1.0, 10),
    scoring='accuracy'
)
plt.plot(sizes, train_scores.mean(axis=1), label='Train')
plt.plot(sizes, val_scores.mean(axis=1), label='Val')
plt.legend(); plt.show()
Sources
  • C. Perlich, F. Provost & J. S. Simonoff, “Tree Induction vs. Logistic Regression: A Learning-Curve Analysis”, Journal of Machine Learning Research 4, 2003
  • P. Domingos, “A Few Useful Things to Know about Machine Learning”, Communications of the ACM 55(10), 2012

Last reviewed October 2026 · How this site checks its content · Report a mistake

Linked from 4
← Previous
Comparing Model Runs
Open in the full reader, with the topic sidebar