In this article
Before you start
This page sits in the machine learning algorithms learning path and uses ideas from statistics for machine learning.
Why interviewers ask this
A model that scores perfectly on its own training data can still fail with the first real user, so this question tests whether a candidate evaluates on data the model has not seen. Candidates report it in machine learning interviews. Expect it to lead into follow-ups on regularization, cross-validation and learning curves.
A weak answer says "I look at accuracy" or "I check that the training loss is low." A strong answer names the comparison, the held-out data it needs and the signature of the gap. A Staff-level answer adds what the curves say about the remedy, and the checks, leakage and split mismatch, that decide whether the gap means what it seems to mean.
Overfitting detection from first principles
- Validation curve
- A validation curve is a plot of the training score and the validation score against the value of one hyperparameter, so the point where the two scores part ways shows where the model starts to overfit.
- Learning curve
- A learning curve is a plot of the training score and the validation score against the number of training samples, so it shows whether more data would shrink the gap between them.
In plain words
Think of a student who memorizes the answers to last year's exam. On that exact exam the student scores perfectly. On a new exam with different questions the score drops. The student learned the answers, not the subject. A model that overfits behaves the same way.
The analogy breaks in one place. A student knows when they memorized, but a model gives no warning. You must set the new exam yourself, and it must be truly new. If the model has seen it, the test shows nothing.
In one precise sentence, you determine overfitting by measuring one metric on the training data and on held-out data, and a large drop from the first to the second is the sign. Google's Machine Learning Crash Course calls generalization the opposite of overfitting and names two common causes: an overly complex model and unrepresentative training data.
Step-by-step description
- Keep data the model never trains on.
- Compare training and validation scores.
- A validation curve shows where the gap opens.
- A learning curve shows if more data helps.
- Check leakage and the split before blaming the model.
- Hold out data the model never trains on.
- A high training score beside a low validation score means overfitting.
- Rule out leakage and a mismatched split before blaming the model.
Step 1: Hold out data the model never sees
Hold out data the model never trains on, because a model's score on its own training data cannot show overfitting. The scikit-learn cross-validation guide calls learning the parameters and testing on the same data a methodological mistake: a model that repeats the labels it has seen would score perfectly and still fail on unseen data.
Cross-validation (CV) is a method that splits the data into k folds, trains on k minus 1 of them, validates on the remaining fold, and repeats until every fold has been the validation fold once. With 30 samples and 10 folds, each round trains on 27 samples and validates on 3.1 Time-ordered data needs a time-based split, not a shuffled one, because shuffling inflates the validation score.
The trap sits here. Once you pick settings by watching the validation score, that score is biased, as the scikit-learn learning-curve guide warns. Keep a test set untouched until the final check. You now have honest held-out scores to compare.
Step 2: Score both sides and read the gap
A high training score beside a low validation score means overfitting. The scikit-learn guide puts it this way: when both scores are low the estimator is underfitting, and a low training score with a high validation score is usually not possible.
Underfitting is the case where a model is too simple to capture the pattern, so both scores are low. Subtract the validation score from the training score to get the generalization gap.
The scikit-learn polynomial example shows how large the effect can be. It fits 30 noisy samples of a cosine curve and reports 10-fold CV mean squared error (MSE) of 0.408 for degree 1, 0.0432 for degree 4 and 1.83e+08 for degree 15 (scikit-learn 1.9.1 example). The degree-15 error is about 4.2 billion times the degree-4 error, and the degree-1 error is about 9.4 times worse than degree 4.1 Degree 15 matches the training points almost perfectly but not the true function; degree 1 is too simple.
Step 3: Vary complexity with a validation curve
A validation curve shows where overfitting starts by sweeping one hyperparameter and plotting both scores. A hyperparameter is a setting you choose before training, such as the maximum depth of a decision tree. The scikit-learn validation curve guide shows that a validation curve computes training scores as well as validation scores, which is what makes the gap visible. Sweep the setting over a sensible range and plot both lines on one chart.
| Tree depth | Training score | Validation score | Gap |
|---|---|---|---|
| 1 | 0.71 | 0.70 | 0.01 |
| 3 | 0.83 | 0.81 | 0.02 |
| 6 | 0.93 | 0.85 | 0.08 |
| 12 | 0.99 | 0.82 | 0.17 |
| 20 | 1.00 | 0.79 | 0.21 |
Training score rises to 1.00 at depth 20 while the validation score peaks at 0.85 at depth 6.1 The gap grows from 0.01 at depth 1 to 0.21 at depth 20.1 Choose the setting where validation peaks, not where training is highest.
Text description of the diagram
- Training score rises to 1.00 at depth 20 while the validation score peaks at 0.85 at depth 6.
- The gap grows from 0.01 at depth 1 to 0.21 at depth 20.
Step 4: Vary data size with a learning curve
A learning curve tells you whether more data would shrink the gap. In the scikit-learn documentation a support vector machine with a training score far above its validation score on small data will most likely improve with more samples. For naive Bayes both scores converge to a low value, so more data will not help much.
Take an illustrative overfitting curve. As samples grow from 100 to 6,400, the training score falls from 1.00 to 0.92 and the validation score rises from 0.68 to 0.86, so the gap narrows from 0.32 to 0.06.1 More data is the right remedy there. In an illustrative underfitting curve, both scores sit near 0.62 at 6,400 samples and the gap is 0.00.1 That is a bias problem, so the model needs more capacity or better features, as covered in feature engineering techniques, not more rows.
Step 5: Rule out leakage and a mismatched split
Rule out leakage and a mismatched split before blaming the model, because both distort the gap: leakage can make the gap look smaller than it is, and a mismatched split can make it look larger. Data leakage is the use of information from outside the training data, such as test rows or their statistics, while fitting the model, and it makes held-out scores look better than they are. The scikit-learn pitfalls guide recommends a pipeline so that each step, such as scaling, fits on the training subset and only transforms the test subset.
A gap can also appear with no memorization at all. Google's course lists the conditions for good generalization: examples that are independent and identically distributed (IID), stationary, and drawn from similar distributions in every partition. If the validation data comes from a different population, the score drops for that reason. Distribution shift covers how to detect it. Only after these checks does a large gap point to overfitting.
Knowing it is half the job. Saying it is the other half.
Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.
Start Free Trial →The Staff-level answer
How do you determine if a model is overfitting?
I compare the model's score on its training data with its score on data it has never seen. If training is high and validation is clearly lower, that is overfitting; if both are low, it is underfitting. I take the validation number from cross-validation so one lucky split does not mislead me.
Then I plot a validation curve and a learning curve to see whether a simpler model or more data would help. I keep a test set untouched, because tuning against the validation score biases it. Before I trust the gap, I check for leakage, which inflates the validation score and can hide real overfitting, and for a mismatched split, which can open a gap with no memorization at all.
What makes it Staff-level is the last two sentences: it protects the held-out score from tuning, checks that a small gap is not leakage and that a large gap is not a mismatch, and only then picks a remedy.
The rubric
| Dimension | Weak answer | Strong answer | Staff answer |
|---|---|---|---|
| Correctness | Says high training accuracy means a good model. | Compares training and held-out scores and names the high-train, low-validation signature. | Also names the both-low case and the unlikely reverse case. |
| Depth | Mentions a train/test split only. | Uses cross-validation for a stable estimate. | Adds validation and learning curves to locate the cause. |
| Trade-offs | Offers no remedy. | Names simplifying the model, more data or regularization. | Chooses the remedy from the curves and says when more data will not help. |
| Communication | Rambles through terms. | States the comparison, then the signature, then the check. | Gives the answer in order and flags what could mislead it. |
| Follow-up readiness | Cannot say why a test set is separate. | Explains that tuning biases the validation score. | Raises leakage and split mismatch before being asked. |
Three variants of this question
How do you tell overfitting from underfitting?
Read both scores. Overfitting is a high training score with a clearly lower validation score. Underfitting is both scores low, close together, and a learning curve that flattens.
How can you tell a neural network is overfitting while it trains?
Plot training and validation loss per iteration. Google's course describes the curves as similar at first and then diverging: training loss declines or holds steady while validation loss increases. That divergence is the sign.
Your validation score is much lower than your training score. Is it definitely overfitting?
No. A mismatched split, a non-representative validation set or noise from a very small validation fold can create the same gap. Check the split and the fold sizes first, then confirm with a learning curve.
Common mistakes
- "The training accuracy is high, so the model is good." (wrong) The score that matters is on data the model has not seen. "I compare training accuracy with validation accuracy." (right)
- "I will tune until the validation score is best, then report it." (wrong) Tuning biases that score. "I report the final number on a test set I never tuned against." (right)
- "A big gap always means overfitting." (wrong) Leakage, non-IID data or a different distribution in the validation set can distort the gap. "I rule those out, then read the gap." (right)
- "More data always fixes overfitting." (wrong) Only a large gap at the largest training size suggests that. "The learning curve tells me whether more data would help." (right)
- "Low training score and high validation score means overfitting." (wrong) The scikit-learn guide calls that case usually not possible. "That pattern is unusual. I check whether training-only regularization such as dropout, a small or easier validation set, or leakage explains it." (right)
Follow-up questions
How do you reduce overfitting once you find it?
Match the remedy to the curves. Use a simpler model or fewer features, add regularization (see L1 vs L2 regularization), get more representative data if the learning curve still shows a gap, or stop gradient descent earlier when validation loss starts to rise.
What gap between training and validation score counts as overfitting?
No fixed threshold exists in the sources. A gap is judged against the metric, the noise in the validation estimate and the use case, and a gap that shrinks as data grows is a different problem from one that stays.
Does cross-validation prevent overfitting?
No. Cross-validation gives a better estimate of how the model will do on new data; it does not change the model. Keep a separate test set, because the scikit-learn guide notes that tweaking parameters until the estimator performs optimally risks overfitting on the test set.
Can you overfit the validation set?
Yes. Each choice you make by looking at the validation score leaks a little of it into the model, which biases the score upward. That is why a final test set stays untouched until the end.
- Overfitting is a high training score beside a clearly lower held-out score.
- Honest held-out data is never used for tuning; keep a test set untouched.
- A validation curve shows where complexity starts to hurt; a learning curve shows whether more data helps.
- Both scores low means underfitting, and more data will not fix it.
- Rule out leakage and split mismatch before calling a gap overfitting.
Sources
- Validation curves: plotting scores to evaluate models (User Guide 3.5) — scikit-learn documentation (version 1.9.1), 26 Oct 2026
- Underfitting vs. Overfitting (example) — scikit-learn documentation (version 1.9.1), 26 Oct 2026
- Cross-validation: evaluating estimator performance (User Guide 3.1) — scikit-learn documentation (version 1.9.1), 26 Oct 2026
- Common pitfalls and recommended practices — scikit-learn documentation (version 1.9.1), 26 Oct 2026
- Overfitting - Machine Learning Crash Course — Google for Developers, 26 Oct 2026