TL;DR: Overfitting in machine learning happens when a model learns its training data too closely, including noise and quirks, so it scores very well on that data but poorly on new data it hasn’t seen. The classic warning sign is low training error with much higher validation or test error. The main fixes are more (or more varied) data, a simpler model, regularization, dropout, early stopping and cross-validation. Its opposite, underfitting, is when a model is too simple to learn the real pattern at all.
A model that aces every practice question but fails the real exam has a familiar problem. If you’ve been wondering what is overfitting in machine learning, that’s the short version: the model memorized instead of learning. This guide explains overfitting in plain English, how to spot it, how it differs from underfitting and the techniques engineers use to prevent it.

What is overfitting in machine learning?
Machine learning models learn patterns from examples, called training data. The goal is generalization: performing well on new, unseen data. Overfitting is when a model fits the training examples so precisely that it captures random noise and one-off details as if they were real patterns. Google’s Machine Learning Crash Course describes an overfit model as one that matches the training set so closely it fails to make correct predictions on new data.
Think of a student who memorizes the exact answers to last year’s exam. They’d score 100% on that paper, but change the wording of a question and they’re lost. A student who understood the concepts would do fine on either version. Overfit models are the memorizers.
A simple example
Imagine predicting house prices from size. The real relationship is roughly a gently rising line, plus some random variation. A straight line or gentle curve captures the trend. An overfit model draws a wildly wiggly line that passes through every single training house exactly, including the oddly cheap one sold to a relative. It looks perfect on the training data and makes silly predictions for any new house between those points.
Overfitting vs underfitting
| Underfitting | Good fit | Overfitting | |
|---|---|---|---|
| What happens | Model is too simple to capture the real pattern | Model learns the real pattern and ignores noise | Model learns the pattern plus the noise |
| Training error | High | Low | Very low |
| Validation/test error | High | Low, close to training error | Much higher than training error |
| Bias vs variance | High bias | Balanced | High variance |
| Typical fix | More features, a more complex model, longer training | Keep it | More data, simplify, regularize, stop earlier |
This trade-off is often called the bias-variance trade-off. Bias is error from overly simple assumptions. Variance is error from being too sensitive to the particular training sample. Good models balance the two.
What causes overfitting?
- Too little training data. With few examples, it’s easy for a model to memorize them all.
- A model that’s too complex. A model with many parameters relative to the amount of data, such as a very deep neural network or an unpruned decision tree, has enough capacity to memorize.
- Training too long. Neural networks often generalize better midway through training, then start fitting noise if training continues.
- Noisy or unrepresentative data. Mislabeled examples and outliers get learned as if they were real signals.
- Too many irrelevant features. Extra inputs give the model more ways to find coincidental patterns.
- Data leakage. If test data sneaks into training, a model can look great in evaluation and fail in the real world, which is a related trap rather than overfitting itself.
How to tell if a model is overfitting
The standard approach is to split your data. You train on one part and evaluate on data the model never saw:
- Training set: what the model learns from.
- Validation set: used during development to tune settings and catch overfitting.
- Test set: held back until the end for a final, honest score.
Then compare the numbers. If training accuracy is 99% but validation accuracy is 75%, the model is almost certainly overfitting. Plotting learning curves, meaning training and validation loss over time, makes it visible: training loss keeps falling while validation loss flattens and starts rising. That turning point is where overfitting begins.
Cross-validation gives a more reliable check, especially with small datasets. In k-fold cross-validation, you split the data into k parts, train k times, and use a different part for validation each time. The scikit-learn documentation explains that testing a model on the same data it learned from is a methodological mistake, and cross-validation is the standard way around it.
How to prevent overfitting: 8 proven techniques
- Get more training data. More varied examples make memorization harder and real patterns clearer.
- Use data augmentation. For images, flipping, cropping or rotating creates new training examples from existing ones.
- Simplify the model. Fewer layers, fewer parameters or shallower trees reduce capacity to memorize.
- Apply regularization. L1 and L2 regularization add a penalty for large weights, nudging the model toward simpler solutions.
- Use dropout. In neural networks, dropout randomly switches off some units during training so the network can’t rely on any single path.
- Stop early. Early stopping halts training when validation loss stops improving.
- Select features carefully. Remove inputs that add noise rather than signal.
- Use ensembles. Methods such as random forests combine many models, which tends to average out individual models’ quirks.
Overfitting in large language models
Overfitting isn’t just a classroom concept. Large language models can memorize and repeat chunks of their training text word for word, which raises privacy and copyright concerns. When companies fine-tune a model on a small custom dataset, overfitting is a common risk: the model may parrot the training examples and lose some general ability. Teams typically watch validation loss, keep fine-tuning runs short and use held-out test prompts.
Benchmarks face a similar issue. If test questions leak into training data, a large language model can score well by recall rather than reasoning. That’s one reason researchers keep building new, private evaluation sets.
Quick glossary
- Generalization: how well a model performs on new data.
- Training loss: the model’s error on the data it learned from.
- Validation loss: its error on held-out data during development.
- Regularization: any technique that discourages overly complex models.
- Underfitting: the model is too simple to learn the real pattern.
Bottom line
Overfitting in machine learning means a model has learned its training data too well, noise included, and can’t handle new data. You spot it by comparing training and validation results, and you fix it with more data, simpler models, regularization, dropout and early stopping. Getting this balance right is what separates a model that impresses in testing from one that works in the real world. Next, see how trained models answer requests in our guide to AI inference.




