Error fixMachine Learning · 3 min read · Updated 5 Dec 2026

Model Overfitting: How to Detect and Fix It

Your model scores 99% in training and fails on new data? Detect overfitting with validation curves and fix it with more data, regularisation and simpler models.

QUICK ANSWEROverfitting means a model has memorised the training data, including its noise, instead of learning patterns that generalise. The sign is a big gap: high training accuracy but much lower validation or test accuracy. Fix it by getting more or cleaner data, using cross-validation, simplifying the model, adding regularisation (L1/L2, dropout), early stopping, and removing features that leak the answer.
Model overfitting: signs and fixes
Model overfitting: signs and fixes

How to detect it

SituationTraining scoreValidation scoreDiagnosis
Good fitHighHigh, close to trainingOK
OverfittingVery highMuch lowerModel memorises
UnderfittingLowLowModel too simple or weak features
Suspiciously perfect~100%~100%Check for data leakage

Fix it step by step

  1. Split properly: keep a test set you never touch until the end; use k-fold cross-validation for model choice.
  2. Plot learning curves (score vs training size) and validation curves (score vs model complexity).
  3. Check for data leakage: features created from the target, future information in time-series, or the same customer in train and test.
  4. Simplify: fewer features, shallower trees (max_depth, min_samples_leaf), fewer layers.
  5. Regularise: L2/L1 penalty (C or alpha in scikit-learn), dropout and weight decay in neural networks.
  6. Use early stopping on the validation set for gradient boosting and neural networks.
  7. Get more data or use data augmentation (images, text).
  8. Use ensembles that reduce variance, such as random forests or bagging.

Quick example with scikit-learn

from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestClassifier

for depth in [3, 6, 12, None]:
    m = RandomForestClassifier(max_depth=depth, random_state=42)
    s = cross_val_score(m, X, y, cv=5, scoring="f1")
    print(depth, round(s.mean(), 3))

Pick the depth with the best cross-validated score, not the best training score.

Data leakage: the hidden overfitting

Leakage makes a model look excellent in testing and fail in production. A classic example: predicting loan default with a column "collections_agency_assigned", which only exists after a default. Ask for every feature: "would I know this at the moment I make the prediction?"

Questions

Is a small gap between train and validation scores normal?

Yes. Some gap is expected. Worry when the gap is large or growing as you train longer.

Does more data always fix overfitting?

It usually helps most, but only if the new data is relevant and correctly labelled.