# Overfitting

> Canonical: https://skillalmanac.com/glossary/overfitting | Last verified: 2026-11-24 | Index status: index-eligible

Overfitting is when a machine learning model matches its training data so closely, including its noise, that it makes poor predictions on new data it has not seen.

Also called: overfit, overfitted model.

## In plain language

Overfitting means a fitted model captures training-specific patterns that do not generalize well. A model may improve its training score while its held-out performance stops improving or gets worse. This does not require literal memorization or failure on every new example. Compare appropriate training and held-out results, check for leakage and evaluate the conditions in which the model will be used.

## Technical definition

Overfitting means fitting details of training data that do not generalize well. A large training-versus-held-out error gap can be evidence, but a finite test score is an estimate affected by the sample and evaluation design. IBM describes detection by comparing training error with error on a held-out test set, or by k-fold cross-validation, where each of k subsets serves once as the test set and the scores are averaged. Mitigations it lists are early stopping, more clean data, regularization, including coefficient penalties such as lasso and ridge, or dropout, which randomly zeroes activations during training, feature selection and ensemble methods. Underfitting is inadequate capture of relevant patterns; capacity, features, regularization and optimization can all matter.

## How it shows up when you use agents

If you ask an agent such as Claude Code or Codex to build a model, or to improve one, overfitting is one possible failure. An agent told to "raise the accuracy" can keep adjusting settings until the number on your test file improves, which means the test file has become part of training. An improved score on repeatedly reused test data is not independent evidence of better deployment performance.

The same shape appears with [LLM](/glossary/large-language-model) features. If you tune a prompt against ten examples until all ten pass, you have fitted the prompt to those ten, and new inputs may behave differently. A [fine-tuned](/glossary/fine-tuning) model trained for too long on a small set can also fit its quirks.

What breaks when this is misunderstood: you ship on a number that does not mean what you think. The safer habit is to keep a test set that neither the agent nor the model sees while tuning, check that it shares no duplicates or groups with the training data, and report the training and held-out scores together. The skills below check the splits and the eval set. See [supervised learning](/glossary/supervised-learning), where the problem is most often discussed.

Ask for the gap between training and held-out results, not just the best score. A large gap is the warning sign IBM describes.

## Worked example (illustrative)

Imagine comparing two models on the same well-designed split: one has lower training error but higher held-out error than the other. That pattern motivates checking whether the extra fit captured training-specific details. It is not, by itself, a complete causal diagnosis: leakage, distribution differences and sampling uncertainty also need attention. No empirical model results are claimed in this illustration.

## Common confusions

- **Overfitting versus underfitting.** Underfitting is inadequate capture of relevant patterns; limited capacity, unsuitable features, excessive regularization or insufficient optimization can contribute. Overfitting concerns fitting training-specific patterns that do not generalize; the size of the resulting error depends on the problem.
- **Training score versus held-out score.** A high score on the training data alone says little. IBM's detection method is the comparison with data the model did not train on.
- **Overfitting versus [hallucination](/glossary/hallucination).** Hallucination is a model stating false things in an answer. Overfitting is a training and evaluation failure. They can co-occur but have different fixes.
- **Myth.** More training always improves a model. In fact, more training can improve a model, up to a point: IBM lists training for too long as a cause of overfitting, which is why early stopping exists.

## Worked examples in this catalogue

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A JSON report on train, validation and test files that flags duplicates, shared groups, time leakage and label leakage between the splits.

Why it exercises the concept: A held-out test set only exposes overfitting if it is truly held out. Duplicates or shared groups across splits can make an overfit model look good, and this skill checks for them.

### [llm-eval-test-sets](https://skillalmanac.com/skills/skill-almanac/llm-eval-test-sets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: An eval dataset for an LLM feature, with a checker that reports duplicates, missing graders and imbalance.

Why it exercises the concept: Tuning a prompt or a fine-tuned model against the same few examples fits it to those examples. A separate, validated test set is the check.

### [huggingface-datasets](https://skillalmanac.com/skills/huggingface/huggingface-datasets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A look at Hugging Face datasets through the Dataset Viewer API: metadata, rows, search and filters.

Why it exercises the concept: Inspecting dataset rows and metadata can reveal issues to investigate. Overfitting depends on the learning procedure and evaluation setting as well as the data.

## Related terms

- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [Supervised learning](https://skillalmanac.com/glossary/supervised-learning.md)
- [Neural network](https://skillalmanac.com/glossary/neural-network.md)
- [Fine-tuning](https://skillalmanac.com/glossary/fine-tuning.md)
- [LLM benchmark](https://skillalmanac.com/glossary/llm-benchmark.md)
- [Training data](https://skillalmanac.com/glossary/training-data.md)
- [Underfitting](https://skillalmanac.com/glossary/underfitting.md)

## Sources

- [Machine Learning Glossary (entry: overfitting)](https://developers.google.com/machine-learning/glossary#overfitting), Google for Developers (accessed 2026-11-23)
- [What is Overfitting?](https://www.ibm.com/think/topics/overfitting), IBM (accessed 2026-11-23)
- [Underfitting vs. Overfitting](https://scikit-learn.org/stable/auto_examples/model_selection/plot_underfitting_overfitting.html), scikit-learn documentation (accessed 2026-11-23)
- [Dropout layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dropout), TensorFlow (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
