Overfitting: How models mistake chance in a finite sample for regularity
Starting from the separation of empirical risk and unknown risk, learn to read training/validation curves, recognize leakage, repetition, and tuning contamination, and understand the boundaries of capacity, double descent, and large model memorization.
- Which combinations of training and unknown risk do underfitting, reasonable fit, and overfitting correspond to?
- Why can a “training score of 100%” be either normal or a danger signal?
- How can you distinguish overfitting, distribution shift, and optimization failure from training/validation curves?
- Why can random splitting be fooled by the same user, future information in time, or near-duplicate samples?
- Which overfitting paths do regularization, more data, early stopping, and smaller models cut off?
1Why the True Objective Is Not on the Training SetMotivation
Model training only ever sees a finite sample; why do we nevertheless require it to answer on future data it has never seen?
The training set is a single finite sample from an unknown data distribution. It simultaneously contains stable regularities, sampling fluctuations, measurement noise, and incidental identifiers. The optimizer only knows how to reduce training loss, not which part can transfer. When model capacity is sufficient, it will exploit both regularities and accidents.
Therefore training accuracy is not the final objective, but evidence that the model fits the samples it has seen. What we actually care about is the risk of the same task under new users, new times, new devices, or other deployment conditions. When the model mistakes chance occurrences in the training samples for regularities, its fit to the training data will continue to improve, yet this may not transfer. High training accuracy only indicates fit to the samples already seen; whether it can transfer must be judged by independent evidence that represents the deployment conditions.
2How to distinguish underfitting, a reasonable fit, and overfittingThree states
“Poor model performance” is not enough; what do the combinations on the training and validation sides respectively indicate?
| State | Training performance | Independent validation performance | Priority action |
|---|---|---|---|
| Underfitting/insufficient optimization | Poor | Also poor, gap may not be large | Improve features, capacity, objective, or optimization |
| Reasonable fit | Good | Close to training and meets task threshold | Check slices, stability, and deployment shift |
| Overfitting | Continues improving | Stagnates or worsens, gap widens | Check leakage, data, regularization, and stopping point |
| Distribution shift | Good | May be good if validation also comes from the old distribution; poor in deployment | Rebuild evaluation representative of deployment conditions |
3What lies between empirical risk and true riskMathematics
How can formulas clarify what the model is actually minimizing and what we truly want to know?
First, let's establish the notation:f is the model being evaluated,n is the number of training samples,i is the sample index,xᵢ and yᵢ are the input and target of the i-th sample,L is the loss function that measures the difference between prediction and target,Pdeploy is the deployment data distribution,E denotes taking expectation over that distribution.
The former is the computable training empirical risk, and the latter is the expected risk over the deployment distribution. Overfitting manifests as R̂_train is very low while R does not decrease in tandem. The validation set gives R a finite-sample estimate, but it itself also has variance, and it is meaningful only when it represents the deployment distribution and has not been leaked by training or hyperparameter tuning.
This gap is a diagnostic signal, not a universal score across datasets; training augmentation, loss weighting, or different sample difficulties can also make the numerical scales on the two sides not entirely consistent. Only after first confirming that the scales on both sides are comparable, when the training empirical risk keeps decreasing while the validation risk no longer improves, does the generalization gap constitute a meaningful overfitting signal.
4How Training and Validation Curves Expose the Stopping PointVisualization
Why does overfitting often not occur suddenly at the end of training, but rather as a gradually expanding process?
Scroll horizontally to view the full diagram on small screens.
If the training and validation losses are both high and not decreasing, it is more likely underfitting, a learning rate problem, or a data pipeline issue. If training loss decreases but validation loss is far higher from the start, suspect the data split and distribution first. Validation loss first improving and then continuing to worsen is the classic overfitting trajectory during training. The candidate early-stopping point comes from the region where the validation curve turns from decreasing to increasing, not from an isolated fluctuation; in practice, confirm it with a patience window and multiple random seeds.
5Complete numerical example: how lower training error selects a worse modelSimulation experiment
In the running example, which model would training error alone choose, and which would independent validation choose?
| Polynomial degree | Training MSE | Validation MSE | Observation |
|---|---|---|---|
| 1 | 0.82 | 0.88 | Poor on both: underfitting |
| 3 | 0.24 | 0.31 | Captures the main curvature |
| 5 | 0.16 | 0.22 | Best on this validation set |
| 10 | 0.08 | 0.39 | Starts chasing noise |
| 15 | 0.01 | 1.47 | Almost passes through the training points, and oscillates wildly outside the interval. |
These numbers are only a teaching simulation, but the reasoning is real: if you choose the model by training MSE, you would choose degree 15; with independent validation, you would choose degree 5. The validation set is not “preventing the model from learning”, but rather provides another piece of evidence about unknown risk.
6Why Data Leakage Can Disguise Itself as Perfect GeneralizationData Boundary
When both training and validation curves look good, why should your first reaction still be to check the split?
| Leakage Type | Shortcut exploited by the model | Correct Split |
|---|---|---|
| Multiple records for the same user | User habits, device, or identity features | Group by user/entity |
| Future information | Post-hoc fields unavailable at prediction time | Rolling time-based split |
| Chunks from the same document | Adjacent paragraphs nearly paraphrase each other | Group by document first, then chunk |
| Augmented image copies | Texture from the same original image | Group by original sample before augmentation |
| Preprocessing fitted on full data | Validation distribution leaks into standardization/feature selection | Fit transforms only on training folds |
| Benchmark answers enter training | Directly memorize questions or rewrites | Deduplication, time isolation, contamination auditing |
After leakage, validation is no longer independent, and a high score cannot estimate deployment risk. When you find that the same user, future information, or near-duplicate samples cross split boundaries, you must reconstruct the splits by the correct entity or time unit and rerun the entire selection process; regularization cannot repair this evidence contamination.
7Why can't the validation set and test set be combined?Evaluation Discipline
The model does not directly backpropagate on the test set — why does repeatedly looking at test scores still count as learning?
Every time you choose an architecture, prompt, loss, threshold, or random seed based on some score, you feed information from that data back into the system. The validation set's job is to absorb this kind of hyperparameter tuning; the test set should provide a nearly one-time final estimate after the process is frozen. If test results influence the next round of development again, the test set has already become a new validation set and can no longer serve as independent final evidence; you need to build a separate unseen evaluation.
- Training set: fit parameters.
- Validation set: select hyperparameters, stopping point, and threshold.
- Test set: final estimate after the process is frozen.
- Deployment monitoring: check the real-world distribution and feedback loops; do not replace them with static tests.
8Why Model Capacity and Overfitting Are Not a Simple Monotonic RelationshipModern frontier
Is having more parameters than samples enough to conclude overfitting?
The classical bias-variance curve reminds us that insufficient capacity leads to underfitting, and variance may rise as capacity increases. But modern deep networks often generalize even when parameters outnumber samples and training error is zero; in some settings, test error first decreases, then increases, and then decreases again as capacity grows, a phenomenon called double descent.
This does not overturn overfitting; rather, it shows that “parameter count” is not the only measure of effective complexity. Architecture, initialization, optimizer, data augmentation, training duration, and data structure jointly determine which solutions optimization actually favors; double descent is manifested only when test error falls, then rises, and then falls again as capacity changes. Regardless of the curve shape, in the end we must rely on evidence from an independent distribution, not replace measurement with parameter count.
9What overfitting looks like in large language models and fine-tuningLLM
Large models train on huge amounts of data; why do they still memorize, contaminate benchmarks, or degrade during small-data fine-tuning?
Pre-training can memorize rare, repeated, or highly identifiable sequences; if benchmark questions appear in training as verbatim text or near paraphrases, evaluation will mistake memory for reasoning. Small-data fine-tuning can quickly memorize wording and format, sacrifice base capabilities, or adapt only to a few prompt templates. When similar questions score abnormally high and scores plunge after rewording, further check whether verbatim text or near paraphrases have been mixed into training, and use out-of-time benchmarks to verify capability.
| Scenario | Overfitting signs | Evidence and mitigation |
|---|---|---|
| Pre-training repetition | Rare text reproduced verbatim | Deduplication, memorization probes, privacy evaluation |
| Benchmark contamination | Similar questions score abnormally high, then plummet after rewording | Out-of-time benchmarks, near-duplicate audits, dynamic questions |
| Small-sample fine-tuning | Works well on training format, fails when paraphrased | Out-of-template held-out slice, fewer epochs, PEFT/early stopping |
| Preference overfitting | Caters to reviewer style, degrades on real tasks | Diverse reviewers, independent capability and safety regression |
10Which Memory Path Does Each Mitigation Method Cut?Engineering
"Adding regularization" is not a button; what exactly do the different methods change?
| Method | What it changes | When it may be ineffective/harmful |
|---|---|---|
| More independent high-quality data | Reduces the proportion of chance patterns and expands coverage | New data is duplicated, from the same source, or poorly labeled |
| Data augmentation | Declares invariances that should keep labels unchanged | Transformation actually changes the meaning |
| Weight decay/Dropout | Restricts parameter or representation co-adaptation | Further harms when already underfitting |
| Early stopping | Limits the time spent continuing to fit noise | Validation set is noisy or has leaked |
| Reducing capacity | Shrinks the set of expressible functions | Loses true regularities and transferable features |
| Group/time split | Restores evaluation independence | Not mitigating the model, but repairing the evidence |
To choose a method, first identify whether overfitting comes from data duplication, model degrees of freedom, training for too long, or evaluation contamination, then address the corresponding part in the table. If both training and validation are poor, the problem is more likely in capacity, features, objective, or optimization; continuing to add regularization at this point is usually treating the wrong cause.
11Connecting the entire causal chainSynthesis
From limited samples to trustworthy deployment judgments, which boundaries must be maintained along the way?
- The deployment distribution produces finite training samples, which contain both regularities and randomness.
- The loss and optimizer reward only decreases in training empirical risk.
- Sufficiently flexible models exploit noise, repetition, and non-transferable shortcuts.
- Independent validation estimates the unknown risk and reveals the generalization gap.
- Grouping, time, and deduplication rules ensure validation is truly independent.
- Validation is used to select capacity, regularization, thresholds, and stopping points, so it is gradually consumed.
- After freezing the pipeline, an unseen test set is used for the final estimate.
- After deployment, continue monitoring distribution drift and real harm, because static evaluation is still not reality itself.
12Common MisconceptionsDisambiguation
| Misconception | More accurate statement |
|---|---|
| 100% training accuracy definitely means overfitting | It is only a risk signal; on separable data, getting all training examples correct can still be normal; you need to look at independent generalization. |
| Poor test performance definitely means overfitting | It could also be distribution shift, evaluation implementation errors, or different label conventions. |
| Having more parameters than samples necessarily means memorization | Effective complexity is jointly determined by architecture, optimization, data, and implicit preferences. |
| Adding Dropout always improves validation | When already underfitting, with sufficient data, or with strong other regularization, it may not help. |
| If the test set never enters the gradients, you can look at it repeatedly | Human selection is also information feedback, and it can cause the system to overfit the test set. |
13Check whether you really understandSelf-test
- In the running example, why does the training error select the 15th-degree polynomial, while the validation error selects the 5th-degree?
- When both training and validation loss are low, why can we still not rule out overfitting or flawed evaluation?
- What shortcut arises when records from the same user are randomly split into training and validation?
- Why does repeatedly modifying the model based on the test set, without doing backpropagation, still contaminate the test?
- When both training and validation are poor, why is 'continuing to add regularization' usually not the first choice?
Reference answers
- A high-degree model can chase training noise, making empirical risk approach zero, but this oscillation does not generalize; validation exposes error on unseen points.
- The two may be near-duplicates, come from the same entity, share future information, or neither represents the deployment distribution.
- The model can identify user/device features rather than learning cross-user patterns; validation overestimates performance on new users.
- Each manual selection writes information from the test score into the system; it has become a hyperparameter-tuning signal.
- When both sides are poor, it is more likely insufficient capacity, features, target, or optimization; imposing extra restrictions on degrees of freedom may make underfitting more severe.
14Concept Dependencies and Further LearningRoadmap
| Direction | What to Read Next | Key Question |
|---|---|---|
| Limiting Fitting Degrees of Freedom | Regularization | How do parameters, data, and the training process each impose preferences? |
| Training Objective Boundaries | Loss Function | Why can surrogate risk keep decreasing yet diverge from the true objective? |
| How to Conduct Trustworthy Evaluation | Model Evaluation | How should slices, confidence intervals, and thresholds be designed? |
| Duplication and Training Data | Training Data Governance | How are lineage, deduplication, licensing, and contamination tracked? |
| Post-deployment Distribution Shift | Data Drift Monitoring | When does static generalization evidence become invalid? |
- Deep Learning — Regularization for Deep Learning: generalization, capacity, and regularization fundamentals.
- Reconciling modern machine-learning practice and the classical bias–variance trade-off: modern interpolation and double descent.
- Deduplicating Training Data Makes Language Models Better: duplicate data, memorization, and evaluation overlap.
- scikit-learn — Common pitfalls and recommended practices: data leakage and pipeline splitting.
The polynomial numerical example is a teaching simulation; the curves, tables, and evaluation workflow are all originally organized by this project and do not correspond to any real experimental results.