Skip to content
AI.info

How machines learn

Overfitting: When the Model Learns the Dataset Too Closely

Understand how flexible models exploit noise, shortcuts, and repeated development feedback, and learn to detect overfitting through curves, slices, and realistic holdouts.

By the end you can

Analogy

The student who learned the answer key

One student memorizes every answer in a practice booklet, printing errors included. The student scores perfectly on repeated questions. The same ideas, asked differently, are a struggle.

An overfit model behaves similarly. It captures training-specific detail that does not transfer. The mechanism is not the same, though: models overfit through many distributed correlations, and store no recognizable example verbatim.

The strong form of that claim has been measured. In 2016 Zhang and colleagues shuffled the labels on a training set at random and trained state-of-the-art image classifiers on it anyway. The networks fit it. Their abstract: “Specifically, our experiments establish that state-of-the-art convolutional networks for image classification trained with stochastic gradient methods easily fit a random labeling of the training data. This phenomenon is qualitatively unaffected by explicit regularization, and occurs even if we replace the true images by completely unstructured random noise.” Random labels carry no signal to learn. Unstructured noise carries no image to recognize. A network that reaches a perfect fit on either has demonstrated capacity and nothing else. That is why a training score, read on its own, is uninformative about everything else. A 2017 paper came at it from the other side: deep networks can memorize noise data, while in practice learning simple patterns first.

Overfitting is about a relationship between performances

A model overfits when its behavior is substantially better on data that influenced fitting than on new cases drawn from the intended use conditions. That difference is often called a generalization gap.

The gap alone needs context. Training and validation may differ because of distribution shift, data quality, preprocessing mismatch, or a harder validation population. Investigation should confirm that the partitions are comparable for the claim being made.

Here is that gap on a system already running in hospitals. Epic's proprietary sepsis prediction model was validated from the outside, on 27,697 patients across 38,455 hospitalizations at Michigan Medicine between 6 December 2018 and 20 October 2019. Andrew Wong and colleagues published the result in JAMA Internal Medicine on 21 June 2021: “Our observed hospitalization-level model performance (AUC, 0.63) was substantially worse than that reported by Epic Systems (AUC, 0.76-0.83) in internal documentation (shared with permission)”. That 0.63 carried a 95% confidence interval of 0.62–0.64. The shortfall is not sampling noise.

A second, independent team measured the same vendor model again, in two county emergency departments, and published in November 2024: 14.7% sensitivity within a 6-hour window, and a median alert lead time of 0 minutes. Nothing about the model changed between the developer's number and these two. The data it was scored on did.

0.76–0.83 in the developer's documentation and 0.63 measured at Michigan Medicine are the same model: the gap lives in the evaluation, not in the parameter count.

Visual

Four routes to a model that knows too much about development data

Overfitting can occur at several levels. Each of the four below has a documented case in this lesson: a convolutional network fitting a random labeling, a classifier reading a photographer's source tag, a public leaderboard tuned for months by thousands of practitioners, and a search-term model rebuilt around whatever had correlated with last winter.

FigureHierarchy · 4 levels
  • Example-level fit

    The model captures noise, outliers, rare combinations, or near-duplicate content.

    • Feature shortcut

      An unstable identifier, template, or environment cue substitutes for the intended signal.

      • Hyperparameter tuning

        Repeated choices adapt the procedure to one validation set.

        • Researcher overfitting

          The whole project changes after seeing the same benchmark or test results.

Case

The horse tag: a classifier that was reading the watermark

A Fisher-vector classifier scored competitively on the PASCAL VOC 2007 “horse” class. It was not looking at horses. It was reading a photographer’s source tag printed on about a fifth of the horse images — “a striking artifact of the dataset that so far had gone unnoticed”, in the words of the team that found it. Lapuschkin and colleagues published the case in Nature Communications on 11 March 2019, in unusual detail.

Cutting the tag out of horse images weakened the model’s decision. Pasting the same tag onto a photograph of a Ferrari made the classifier’s prediction, in the authors’ words, “swiftly change[] from ‘car’ to ‘horse’ … a clearly invalid decision”. The held-out score was real. What it measured was not.

Visual

The classic divergence—and its caveats

Learning curves often show training improving continuously while validation improves, plateaus, and then deteriorates.

That shape is a common observation, not a law. The exception has a name and a measurement behind it. Belkin and three colleagues documented it in PNAS on 6 August 2019: “This "double-descent" curve subsumes the textbook U-shaped bias–variance trade-off curve by showing how increasing model capacity beyond the point of interpolation results in improved performance.” Test risk falls, rises toward a peak as capacity approaches the interpolation threshold, and then falls again on the far side. A curve that has turned upward is not proof that the best model is behind you.

The effect survives in modern deep networks. Nakkiran and colleagues reproduced it in the Journal of Statistical Mechanics on 29 December 2021. They showed it occurs as a function of training epochs as well as of model size, which puts it directly in the path of an epoch-based stopping rule. They also identified regimes in which quadrupling the number of training samples hurts test performance.

FigureTimeline · 4 stops
  1. Early training

    Both training and validation improve as stable structure is learned.

  2. Useful middle

    Validation reaches its best observed region while the training fit continues.

  3. Late specialization

    Training still improves, but validation worsens as the model follows training-specific detail.

  4. Checkpoint choice

    A validation-based stopping rule may select an earlier model rather than the final update.

Example

Conditions that make overfitting easier

Overfitting risk rises when flexibility grows faster than reliable evidence. Google Flu Trends is the worked example of exactly that ratio.

The methodology matched the best of 50 million search terms to 1,152 data points. Its developers had to discard seasonal terms — high-school basketball among them — that correlated with the CDC series without predicting flu. Lazer and colleagues took the system apart in Science on 14 March 2014: “This should have been a warning that the big data were overfitting the small number of cases—a standard concern in data analysis. This ad hoc method of throwing out peculiar search terms failed when GFT completely missed the nonseasonal 2009 influenza A–H1N1 pandemic. In short, the initial version of GFT was part flu detector, part winter detector.” From 21 August 2011 to 1 September 2013 the system reported overly high flu prevalence in 100 out of 108 weeks. It overshot the 2011–2012 level by more than 50%.

An independent team had already reached the same diagnosis. Writing in PLOS Computational Biology on 17 October 2013, they documented GFT “completely missing the first wave of the 2009 influenza A/H1N1 pandemic” and “greatly overestimating the intensity of the A/H3N2 epidemic during the 2012/2013 season”.

  • Small numbers of independent entities relative to model capacity — 1,152 weekly observations is a small number however large the candidate feature pool is.
  • Noisy, inconsistent, or weak labels that invite fitting annotation accidents.
  • High-dimensional features with many opportunities for chance correlation: among 50 million search terms, something will track any 1,152-point series, and high-school basketball did.
  • Repeated tuning on the same validation set or public leaderboard.
  • Duplicates, overlapping windows, and identity cues that make training cases unusually recognizable.
  • Rare slices represented by too few examples to estimate stable behavior.

Case

120 Kaggle competitions: where reusing a holdout actually bites

How much does repeated tuning actually cost? Seven researchers measured it across 120 Kaggle competitions and reported the answer at NeurIPS 2019. Each competition is months of thousands of practitioners tuning against a public leaderboard, then a single ranking on a private test set used once. The classification competitions, they found, “show little to no signs of overfitting”. Effect sizes among the top submissions were “typically small (e.g., less than 1% classification accuracy)”.

The exceptions are the point. “While there are some outlier competitions in the data, these competitions usually have pathologies such as non-i.i.d. data splits or (effectively) small test sets.” Validation reuse is not harmless. The harm concentrates where the holdout is small or its rows are not independent — which is where most projects live, and where Kaggle mostly does not.

The other half of the question is what happens when you build a genuinely fresh test set. Recht and colleagues rebuilt the CIFAR-10 and ImageNet test sets by replicating the original collection processes. From their 2019 abstract: “We evaluate a broad range of models and find accuracy drops of 3% - 15% on CIFAR-10 and 11% - 14% on ImageNet. However, accuracy gains on the original test sets translate to larger gains on the new test sets. Our results suggest that the accuracy drops are not caused by adaptivity, but by the models' inability to generalize to slightly "harder" images than those found in the original test sets.” A double-digit drop — and the authors' own reading is that years of benchmark reuse are not what caused it.

That reading was then tightened by a separate group. On 19 May 2020 they re-measured the ImageNet-v2 gap, correcting for statistical bias in the replication procedure. Only 3.6% ± 1.5% of the original 11.7% ± 1.0% drop remained unexplained. Most of the alarming number was an artifact of how the replacement test set was built. What survives is small — and still not zero.

Key idea

A large gap is not always fixed by regularization

If validation comes from a later time, new site, or different population, the gap may reveal distribution shift rather than classic overfitting. If preprocessing differs, the problem is pipeline mismatch. If labels have different definitions, the comparison is invalid.

Regularization is useful only after the evidence and the split are understood.

One study shows how far that diagnosis can travel. Pneumonia classifiers were trained on 158,323 chest radiographs from three institutions, then tested across sites; Zech and colleagues published the result in PLOS Medicine in November 2018. The Mount Sinai model scored AUC 0.802 on Mount Sinai’s own held-out radiographs and 0.717 on the National Institutes of Health set. A model trained on both scored 0.931 internally and 0.815 at Indiana University.

A second experiment explained it. A network trained only to name the source hospital identified 22,050 of 22,062 NIH radiographs and 8,386 of 8,388 Mount Sinai ones. A network trained to name the department within Mount Sinai got 5,805 of 5,805 inpatient radiographs right. Pneumonia was present in 34.2% of the Mount Sinai images and 1.2% of the NIH images. A model that could tell the sites apart had a shortcut worth a great deal of apparent skill. Regularization would not have touched it.

Diagnose the source of the gap before applying a standard remedy.

Steps

Separate memorization, shortcut, and shift

A structured investigation prevents a blind search through regularization settings.

Step 1 is not merely good practice. In one domain it is published regulatory expectation. On 27 October 2021 the FDA, Health Canada and the MHRA jointly issued ten Good Machine Learning Practice guiding principles for medical device development. The fourth is titled “Training data sets are independent of test sets” and reads: “Training and test datasets are selected and maintained to be appropriately independent of one another. All potential sources of dependence, including patient, data acquisition and site factors are considered and addressed to assure independence.”

Three regulators name the dependencies by category: patient, data acquisition, site. The Mount Sinai result is precisely what the site clause exists to catch. A partition check that stops at “no duplicate rows” has addressed one of the three.

FigureProcess · 6 steps
  1. 1. Verify the partitions

    Check duplicates, groups, time, labels, and preprocessing consistency.

  2. 2. Compare curves

    Measure training and validation behavior across data size and capacity.

  3. 3. Inspect nearest cases

    Look for repeated or highly similar training examples behind validation predictions.

  4. 4. Test shortcuts

    Remove identifiers, source cues, and unstable feature groups.

  5. 5. Change evidence

    Use a new time, site, entity, or fresh holdout to see what transfers.

  6. 6. Apply control

    Add data, regularization, early stopping, simpler capacity, or a narrower scope.

Learning curves reveal whether more evidence may help

Train models on progressively larger training subsets. Evaluate them under the same validation policy. If training performance declines slightly while validation improves and the gap narrows, additional representative data may help.

If both curves plateau at poor performance, the bottleneck may be underfitting or weak signal. If validation remains unstable because the holdout is tiny, better evaluation design may be more urgent than more training data.

The monotone reading of that curve has its own measured exception. Nakkiran and colleagues identified regimes in which quadrupling the number of training samples hurts test performance. More data is the usual answer. It is not an unconditional one.

Comparison

Responses and what they actually change

The same visible gap can justify different interventions, and this lesson's cases sort them. Explicit regularization did not stop convolutional networks from fitting a random labeling, so a penalty term is not a general answer to memorization. More training samples hurt test performance in some of the regimes Nakkiran and colleagues identified, so more data is a strong default rather than a guarantee. The horse classifier needed the photographer's tag removed — that is task and feature redesign, not capacity control. And Epic's sepsis model needed an external cohort of 38,455 hospitalizations before anyone could see there was a gap to remedy at all.

FigureComparison · 4 columns

More representative data

Reduces uncertainty and exposes more stable variation.

  • Useful when coverage is limited
  • Must add independent information
  • Does not repair leakage
  • Can be expensive to label

Capacity or regularization control

Restricts the fitted function or encourages simpler behavior.

  • Useful when training fit is excessive
  • Includes penalties and structural limits
  • Requires retuning
  • May reintroduce underfitting

Early stopping

Selects a checkpoint before late training specialization.

  • Uses validation evidence
  • Cheap when checkpoints exist
  • Does not fix a bad split
  • May vary with noise

Task or feature redesign

Removes shortcuts or aligns evidence with the intended problem.

  • Addresses root causes
  • May reduce headline metrics
  • Improves interpretability of the claim
  • Can require new collection

Key takeaways