الانتقال إلى المحتوى
Machine LearningSupervised Learning· 6 دقائق للقراءة

Overfitting: Why 99% Training Accuracy Is a Warning, Not a Win

A model can score perfectly on labels that are pure noise. Only data it never trained on tells learning from memorizing.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A teammate trains a decision tree on last quarter's customers to predict churn, and the notebook prints a training accuracy of 1.000. The pull request says "model works perfectly", the reviewer sees a perfect number and approves it. A few weeks after launch, the retention team reports that the list of at-risk customers looks almost random. Nothing broke in production; the model was never as good as that number suggested.

The common misconception

Many developers read high training accuracy as proof that a model has learned the problem. It's an easy belief to hold:

  • In ordinary software, passing the tests means the code works. Training data feels like the test suite, so a high score on it feels like green CI.
  • Low training accuracy really is a problem: a model that can't fit the data it trained on is underfitting. So pushing that number up looks like progress.
  • Large modern models often reach near-perfect training accuracy and still perform well on new data, so a high training score doesn't look suspicious on its own.

The half-truth is that a model has to fit its training data reasonably well to be useful. But training accuracy can't tell you whether it got there by learning patterns that carry over to new data or by memorizing the rows it saw.

What actually happens

A model is tuned to make its training examples come out right. Scoring it on those same examples grades the exam with the answer key the student studied from.

Training accuracy measures memory

The scikit-learn user guide calls testing a model on the data it learned from "a methodological mistake": a model that simply repeats the labels it has seen would get a perfect score and predict nothing useful. That's . Google's Machine Learning Crash Course describes it as a model that matches, or memorizes, the training set so closely that it fails on new data. The opposite is : making good predictions on data the model has never seen.

Proof: a perfect score on noise

Here's the experiment. Train a decision tree on scikit-learn's built-in breast cancer dataset, then shuffle the labels so they no longer relate to the features at all, and train again.

Python
import numpy as npfrom sklearn.datasets import load_breast_cancerfrom sklearn.tree import DecisionTreeClassifierX, y = load_breast_cancer(return_X_y=True)tree = DecisionTreeClassifier(random_state=0).fit(X, y)print(f"real labels:  train {tree.score(X, y):.3f}")  # 1.000y_noise = np.random.default_rng(0).permutation(y)  # labels now mean nothingtree.fit(X, y_noise)print(f"noise labels: train {tree.score(X, y_noise):.3f}")  # 1.000

The first script prints 1.000 twice. With no limits, the tree keeps splitting until every leaf holds a single class, so it can memorize any labeling of distinct rows, meaningful or not. Deep networks do the same: Zhang et al. showed that state-of-the-art image classifiers easily fit a random labeling of their training data. A training score can't separate learning from memorizing.

The second script uses : five times, it trains on four fifths of the data and scores on the fifth it held out. Now the difference shows. On noise, validation accuracy falls to 0.504, a coin flip. On the real labels, the full tree still scores 1.000 in training but 0.917 on held-out rows.

The gap is the signal

Look at the last line. Requiring at least 10 samples per leaf drops training accuracy to 0.960 and raises validation accuracy to 0.931. The gap between the two shrinks from 0.083 to 0.029. Lower training accuracy, better model: that's only visible when you print both numbers.

For models trained step by step, such as neural networks and gradient boosting, the Crash Course shows the same thing over time: training and validation loss move together at first, then diverge, with training loss still falling while validation loss climbs.

Why models overfit

The Crash Course names two main causes: a model that's too complex, and a training set that doesn't represent real data. A flexible model on a small dataset is the classic combination. scikit-learn's underfitting vs overfitting example fits polynomials to 30 noisy points: degree 4 approximates the true curve almost perfectly, while degree 15 learns the noise, and its cross-validated error explodes.

The Crash Course's fixes for diverging loss curves follow from that: make the model simpler, for instance with fewer features, increase regularization, and make sure the training and test sets are statistically equivalent. For trees, "simpler" means limits such as max_depth or min_samples_leaf.

MythReality
99% training accuracy means the model learned the problemIt can mean the model memorized the rows; a tree scores 100% on random labels
Higher training accuracy is always betterIn the example, training accuracy fell from 1.000 to 0.960 and validation rose
The test set exists to confirm the numberIt exists to estimate performance on data the model never saw
More training fixes overfittingOnce the loss curves diverge, more training widens the gap

How to apply it in your project

  1. Never report a training score alonePass return_train_score=True to cross_validate and print training and validation scores side by side. A single number in a pull request should be the validation score.
  2. Hold out a test set firstSplit before any exploration or tuning, and don't look at the test set until you've picked your final model.
  3. Watch the gap, not the peakA large gap between training and validation means overfitting. Compare candidate models by validation score, not by how well they fit the training rows.
  4. Simplify before adding moreLimit the tree's depth or leaf size, drop weak features or increase regularization, then check whether validation improves.
  5. Make the splits representativeThe Crash Course's conditions for generalization: examples are independent, the data doesn't change much over time, and training, validation and test sets come from the same distribution. Shuffle before splitting unless the data is ordered in time.

Key takeaways

  • Training accuracy measures how well a model remembers its training rows, not how well it predicts new ones.
  • A model can score 100% on labels that are pure noise, so a high training score proves nothing on its own.
  • Judge a model by held-out data, and read the gap between training and validation as the overfitting signal.
  • Fix overfitting by simplifying, regularizing and making your data representative, not by training harder.

📚 المصادر

  1. Overfitting — Google Machine Learning Crash Course
  2. Interpreting loss curves — Google Machine Learning Crash Course
  3. Cross-validation: evaluating estimator performance — scikit-learn User Guide
  4. Underfitting vs. Overfitting — scikit-learn examples
  5. Zhang et al., Understanding deep learning requires rethinking generalization (ICLR 2017)

التعليقات (0)