Plain-language guides to artificial intelligence

Why Models Memorize Instead of Learn: Understanding Overfitting

what is overfitting in machine learning

Does your model shine on training data but stumble on anything new? That is the short answer to what is overfitting in machine learning: a model memorizing its training data, noise included, instead of learning patterns that carry over.

This guide is a close-up of one problem within the wider topic of what is artificial intelligence.

Item Value
Core symptom Low error on training data, high error on test data
Where the causes lie Model, data or training methods
Opposite problem Underfitting: high bias, less variance
Detection method k-fold cross-validation: data split into k equally sized folds
Effect of regularization Limits the amount of variance in the model

These points come from IBM’s overfitting explainer, published 15 October 2021, and TechTarget’s definition. Guidance and terminology can change, so check the sources before you rely on them.

What overfitting looks like in practice

Overfitting happens when a model fits its training data so closely that it can’t make accurate predictions on anything else. IBM describes it as a model that “fits too closely or even exactly to its training data”.

A familiar analogy is a student who memorizes answers instead of understanding concepts. According to GeeksforGeeks, that student scores well on familiar questions but fails when a new question appears, and an overfitted model behaves the same way.

TechTarget gives a hiring example. A model meant to shortlist resumes overly fixates on font choices, rejecting highly qualified applicants for using Helvetica rather than Times New Roman. The font was noise in the training data, yet the model treated it as a rule.

Why do models memorize instead of learn?

Most causes sit in one of three places: the model, the data or the training method. The usual suspects are:

  • A model that is too complex. GeeksforGeeks notes that a model with too many parameters can easily fit noise along with real patterns.
  • Too little data. With limited data, the model may memorize examples instead of learning general rules.
  • Noisy data or outliers. Errors or unusual values can be learned as if they were real patterns.
  • Training for too long. TechTarget says that even with optimized data and model, the model starts learning noise and performs worse the longer it trains.
  • Irrelevant features. Unnecessary inputs increase complexity and make overfitting more likely.
  • Reusing the same validation data. Testing a model repeatedly on the same data can lead to implicit overfitting to a stale data set, as TechTarget points out.

Because these causes overlap, a single fix rarely solves everything. You usually need to look at your data, your model and your training run together.

Overfitting versus underfitting

Underfitting is the opposite failure. IBM explains that it occurs when the model has not trained for enough time, or the input variables are not significant enough to determine a meaningful relationship between inputs and outputs.

The two problems differ in how they err. Underfitted models experience high bias and less variance, while overfitted models show low bias and high variance. Hasty’s computer vision wiki states the relationship as: when bias is high, variance is low, and vice versa.

TechTarget’s resume example shows underfitting too. An underfit model may select all resumes containing specific keywords, such as Java and JavaScript, even if only JavaScript skills are required. The model is too crude to capture the real relationship.

The goal is the middle ground. IBM calls it a sweet spot where the model can establish a dominant trend and apply it broadly to new datasets.

what is overfitting in machine learning Plotted curves
Green lines and multicolored peaks appear on a dark display.

How you can detect overfitting

The simplest check is to hold data back. IBM says part of the training dataset is typically set aside as a test set, and if the training data has a low error rate while the test data has a high error rate, it signals overfitting.

GeeksforGeeks recommends dividing the dataset into training, validation and testing sets. The model learns from the training set, tuning happens on the validation set, and final evaluation is done on the test set to check real-world performance.

For a sturdier estimate, use k-fold cross-validation. IBM describes the process like this:

  1. Split the data into k equally sized subsets, called folds.
  2. Use one fold as the holdout set and train the model on the remaining folds.
  3. Repeat until each fold has acted as the holdout fold, keeping a score after each evaluation.
  4. Average the scores to assess the performance of the overall model.

Learning curves add another view. TechTarget says a learning curve for an overfitting model contains lower error values, but there is a gap between the validation and training results.

Ways to reduce overfitting

No single technique wins every time. These are the ones that IBM and GeeksforGeeks cover most often:

  • Early stopping. Pause training before the model starts learning the noise. The risk is halting too soon, which leads to the opposite problem of underfitting.
  • More clean data. Expanding the training set gives the model more opportunities to find the dominant relationship, but IBM stresses this works best when the data is clean and relevant.
  • Feature selection. Identify the most important features and eliminate the irrelevant or redundant ones.
  • Regularization. Penalize larger coefficients so the model can’t grow too complex. Methods include lasso regularization, ridge regression and dropout.
  • Ensemble methods. Techniques like Random Forest combine multiple models, and averaging predictions makes the final model more stable and less sensitive to noise.
  • Simpler models. TechTarget notes that simpler models are less susceptible to capturing noise or irrelevant patterns.

Each fix has a trade-off. Remove too many features or stop too early and you land on the underfitting side of the sweet spot.

If you want to practise these ideas on real projects, how to learn machine learning is a sensible next read.

Does memorizing always hurt performance?

The classic story says a model that fits its training data exactly will fail on new data. IBM’s page, published 15 October 2021, adds that recent research indicates complex models, such as deep learning models and neural networks, can perform at a high accuracy despite being trained to exactly fit, or interpolate, the data.

IBM explains this through the double descent risk curve: past the threshold of interpolation, performance improves. It also warns that early stopping and regularization can actually prevent interpolation.

The practical lesson is to measure rather than assume. Whatever the model size, a held-out test set tells you whether it generalizes. If you want to compare this with a different style of training, read what is reinforcement learning.

Frequently asked questions

What is overfitting in simple terms?

Show answer

It is a model that has memorized its training data, noise and all, so it performs poorly on new data. Like the student who memorizes answers, it does well on familiar questions and fails on unfamiliar ones.

How do I know if my model is overfitting?

Show answer

Compare errors. If the training data has a low error rate and the test data has a high error rate, that signals overfitting, according to IBM’s page published 15 October 2021. Cross-validation gives a more reliable check.

Is underfitting the same as overfitting?

Show answer

No. Underfitting means the model has not learned the trend at all, with high bias and less variance. Both generalize poorly to unseen data, but for opposite reasons.

Can more data fix overfitting?

Show answer

Often it helps, because a larger training set gives the model more opportunities to find the dominant relationship. IBM adds that this works best when clean, relevant data is added; otherwise you may keep adding complexity.