Overfitting and Generalization — The Central Problem of Machine Learning

If there is one idea that separates people who understand machine learning from people who can run a library, it is this: the goal is never to do well on the data you have, but on the data you don't. A model that nails its training data and fails in production hasn't learned — it has memorized. Overfitting is the central failure mode of ML, and the techniques to fight it (the train/test split, regularization, the bias-variance trade-off) are the discipline's core craft.

Post 1 named generalization as ML’s obsession; this post makes it precise. Everything here — why you never trust training accuracy, why simpler is often better, why you hold data back — exists to answer one question: will this model work on inputs it has never seen? Getting this wrong is the most common and most expensive mistake in applied ML, including in LLM evaluation.

Overfitting vs underfitting

A model can fail to generalize in two opposite ways:

The art of ML is navigating between them to the sweet spot: complex enough to capture the true signal, simple enough not to memorize the noise. This is the bias-variance trade-off: - Bias is error from overly simplistic assumptions (underfitting) — the model can’t represent the truth. - Variance is error from over-sensitivity to the training sample (overfitting) — the model changes wildly with different data. - Lowering one tends to raise the other, and the goal is the balance that minimizes total error on unseen data. Every regularization technique is a deliberate trade of a little more bias for a lot less variance.

The train/test split: never trust training accuracy

The single most important practice in all of ML follows directly: evaluate on data the model never saw during training. You split your data: - Training set — the model learns from this. - Test set — held back, untouched during training, used once to estimate real-world performance. - often a validation set too — for tuning choices (hyperparameters, model selection) without contaminating the final test estimate.

The iron rule: training accuracy is meaningless as a measure of quality, because a sufficiently complex model can memorize the training set perfectly while being useless on new data. Only performance on held-out data tells you whether the model generalized. Violating this — evaluating on data the model saw, or letting test data leak into training (data leakage) — produces impressively wrong results and is the most common way ML projects fool themselves. Cross-validation (rotating which slice is held out, averaging the results) makes the estimate more robust when data is limited. This discipline is exactly why LLM benchmarks obsess over contamination — a model that saw the test questions in training isn’t being measured, it’s being caught cheating.

Fighting overfitting: regularization and friends

Once you can detect overfitting (train accuracy ≫ test accuracy), you fight it with a toolkit, all variations on “prefer simpler models”:

The unifying principle is Occam’s razor applied to models: among models that fit the data comparably, prefer the simpler one, because it’s more likely to have captured the real pattern rather than the noise, and therefore more likely to generalize. Every technique here is a way to enforce that preference.

The throughline: ML’s goal is generalization — performance on unseen data — and its central failure is overfitting (memorizing training noise: great train accuracy, poor new-data accuracy), with underfitting (too simple to capture the signal) as the opposite error. The bias-variance trade-off frames the balance (bias = too-simple error, variance = over-sensitive error; lower total error on unseen data is the target). The non-negotiable practice is the train/test split — training accuracy is meaningless, only held-out performance counts, and leakage/contamination is how projects (and LLM benchmarks) fool themselves — with cross-validation for robustness. Fight overfitting with regularization (penalize complexity — the tunable bias-variance dial), more data, simpler models, early stopping, ensembles, and (for nets) dropout/augmentation — all enforcing Occam’s razor: prefer the simpler model that fits comparably.

Key takeaways

Further reading

Sources & References