In this article
Before you start
This page is one step of the classical machine learning learning path, and the statistics behind noise and error are in the statistics guide.
Why interviewers ask this
A candidate who reports only a training score has told the interviewer nothing about how the model will behave on new data. The overfitting question separates people who know that from people who recite definitions. Candidates report it in machine learning screens and at the start of modeling rounds, usually as the first of several follow-ups about validation, regularization and bias and variance.
A weak answer defines the two words and stops. A strong answer ties each failure to a measurable signal, the training and validation scores, and pairs each with a remedy. A Staff-level answer adds what the remedy costs: a simpler model may raise training error, more data helps only in some cases, and tuning against the validation score uses it up, so a final test set stays untouched. The sections below build that answer one step at a time, with a five-point example you can check by hand.
Overfitting and underfitting from first principles
- Overfitting
- Overfitting is a failure mode in which a model performs well on its training data but poorly on new, unseen data, because it has learned the noise and quirks of the training set and not only the pattern that carries over to new examples.
- Underfitting
- Underfitting is a failure mode in which a model is too simple to capture the pattern in its data, so it scores poorly on the training samples themselves and on new data alike. A straight line fitted to data that follows a curve is the standard example.
- Validation set
- A validation set is a slice of the labeled data held back from fitting and used to measure how a model does on examples it has not seen, so that choices such as model complexity can be compared fairly.
In plain words
Picture two students preparing for an exam from last year's papers. One reads only the chapter titles and cannot answer even last year's questions: that student underfits. The other memorizes every answer word for word, including a typo in the answer key. That student freezes on any new question: that student overfits. The analogy breaks in one place. A model has no understanding to lose. It has only fitted numbers, and the only way to judge them is a score on data held back from fitting.
In one precise sentence: a model underfits when it is too simple for the pattern in the data. It overfits when it is flexible enough to fit the noise. A held-back score reveals which. Generalization is the ability of a model to perform well on new, unseen data, and Google's Machine Learning Crash Course calls it the opposite of overfitting.
Step 1: Underfitting means the model is too simple
Underfitting happens when a model cannot represent the pattern in the data, so its error is high on the training samples and on new data alike. A straight line fitted to a curved relationship is the standard case; it is what linear regression produces when the true relationship is not linear. In the scikit-learn 1.9.1 example, 30 noisy samples of a cosine curve are fitted with polynomials of degree 1, 4 and 15, and the page states that a linear function (polynomial with degree 1) "is not sufficient to fit the training samples".
Scores come from 10-fold cross-validation, which splits the data into ten parts and lets each part take a turn as the held-back part. The mean squared error (MSE) is 0.408 for degree 1 and 0.0432 for degree 4 (scikit-learn 1.9.1 example). You now know that a score on held-back data is how a too-simple model is caught; the next step makes the comparison explicit.
Step 2: Compare the training score with the validation score
Comparing a model's training score with its validation score tells you whether it underfits or overfits. The scikit-learn guide to validation curves gives the rule: when both scores are low the estimator underfits, and when the training score is high and the validation score is low it overfits. Underfitting means both training and validation scores are low. Overfitting means a high training score and a low validation score. The same guide notes that a low training score with a high validation score is usually not possible, so seeing that pattern is a reason to check how the data was split.
| Training score | Validation score | Diagnosis | First thing to try |
|---|---|---|---|
| Low | Low | Underfitting | More flexible model or better input features |
| High | Low | Overfitting | Simpler model, regularization, more representative data |
| High | High | Good generalization | Keep it, and confirm on a test set |
| Low | High | Usually not possible | Check the split and the scoring code |
Models trained by repeated updates, for example with gradient descent, repeat the same comparison over time. Google's course says overfitting shows as diverging loss curves: after a certain number of iterations the training loss declines or holds steady while the validation loss increases (Google, Overfitting). For a classifier that loss is usually cross-entropy loss. No source fixes a gap size that counts as overfit; it is a judgment against what the application needs.
Step 3: Overfitting means the model learns the noise
Overfitting happens when a model is flexible enough to fit the random noise in its training samples, so its training error looks excellent while its error on new data is poor. Google's course names two common causes: unrepresentative training data and overly complex models. In the scikit-learn example the degree-15 polynomial reaches a cross-validated MSE of 1.83e+08, roughly 183 million, against 0.0432 for degree 4, because it "learns the noise of the training data" (scikit-learn 1.9.1 example). The exact degree-15 digits vary between library versions, so the lesson is the size of the gap, not the digits. The scikit-learn course describes the same effect as memorizing noisy variations of the training set that do not generalize.
The table above uses scores, where higher is better; the toy example below uses errors, where lower is better, so for errors the words high and low flip. A five-point example you can check by hand shows the effect. The training points are (0, 1), (1, 3), (2, 2), (3, 5) and (4, 4); they come from the line y = 1.4 + 0.8x plus noise of −0.4, 0.8, −1.0, 1.2 and −0.6 (illustrative).1
Four held-back validation points at x = 0.5, 1.5, 2.5 and 3.5 come from the same line with their own noise of −0.9, 0.9, −0.9 and 0.9 (illustrative).1 Three models are fitted: a flat line at the mean (degree 0), a least-squares straight line (degree 1), and the degree-4 polynomial that passes through all five points.
The straight line recovers the true line, so its training error is 0.72, exactly the average squared training noise, and its validation error is 0.81, exactly the average squared validation noise.1 No model reaches zero error on held-back points, because their noise cannot be fitted. At degree 4 the training error is 0.00 and the validation error is 2.41.1 The flat line is too simple: its training error is 2.00 and its validation error is 2.33.1 A straight line has the lowest validation error, 0.81, in this illustrative example.1
| Model | Training error (MSE) | Validation error (MSE) | Reading |
|---|---|---|---|
| Flat line, degree 0 | 2.00 | 2.33 | Underfits |
| Straight line, degree 1 | 0.72 | 0.81 | Balanced |
| Polynomial, degree 4 | 0.00 | 2.41 | Overfits |
Text description of the diagram
- At degree 4 the training error is 0.00 and the validation error is 2.41.
- A straight line has the lowest validation error, 0.81, in this illustrative example.
Step 4: Move the complexity setting toward the balanced middle
Model complexity is the dial that moves a model between underfitting and overfitting, and the aim is the region in between. A hyperparameter is a setting chosen before training, such as the degree of a polynomial or the maximum depth of a decision tree, that changes how flexible the model can be (scikit-learn course). Raising it lowers training error but, past some point, raises validation error. In the toy example degree 0 underfits, degree 1 balances and degree 4 overfits.1
Where the middle sits depends on the dataset: the course's own tree underfits at shallow depths on its data, and that does not carry over to other data. In k-nearest neighbors (KNN) a very small number of neighbors lets single noisy points steer the output, and a very large number averages away real structure; k-means vs KNN explains the algorithm. To choose the setting, compare validation scores across values. Once you tune on the validation set, its score is biased and no longer a good estimate of generalization (scikit-learn guide source). The test set is a final slice of data used once, after every choice is made, to report the generalization estimate.
Step 5: Fix each failure with its own remedy
Each failure has its own fix, and using the wrong one wastes effort. For underfitting, add capacity or better inputs: a more flexible model, or feature engineering that exposes the pattern. Overfitting is fixed by simplifying the model, regularizing it or adding representative data.
Regularization is a technique that penalizes model complexity during training, so that training minimizes both the loss and the complexity (Google, Model complexity). L1 vs L2 regularization compares the two common penalties. Google adds that simpler models often generalize better, "even if they perform slightly worse on training data" (Google, Model complexity).
More data is the third remedy, with a condition. The scikit-learn guide source says more training data reduces variance but should be collected only if the true function is too complex for an estimator with lower variance. A larger dataset does not make a too-simple model more flexible. This page covers the classical picture. Very large neural networks can behave differently: Belkin et al. (2019) describe a double descent, in which test error falls a second time once a model is flexible enough to fit its training data exactly.
Step-by-step description
- An underfit model scores poorly everywhere.
- Training versus validation names the problem.
- An overfit model has a wide score gap.
- Move the dial toward the middle.
- Match the remedy to the problem.
- Underfitting means both training and validation scores are low.
- Overfitting means a high training score and a low validation score.
- Overfitting is fixed by simplifying the model, regularizing it or adding representative data.
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
What is overfitting or underfitting?
Underfitting means the model is too simple for the pattern, so it does badly on the training data and on new data. Overfitting means it has learned the noise in the training set, so training performance looks great and validation performance is poor. I tell them apart by comparing the two scores, or the training and validation loss curves: both low is underfitting, a wide gap is overfitting. For underfitting I add capacity or better features. For overfitting I simplify the model, add regularization or early stopping, or collect more representative data. I keep a separate test set, because tuning against the validation score biases it.
What makes it Staff-level: it names the diagnostic first, pairs each failure with its own fix, and protects the final estimate with a held-back test set. The spoken structure is define both, name the diagnostic, pair each with its fix, then protect the estimate.
The rubric
| Dimension | Weak answer | Strong answer | Staff answer |
|---|---|---|---|
| Correctness | Mixes up the two terms or defines them only by accuracy | Defines both and links each to the training and validation scores | Also separates overfitting to the training set from distribution shift after deployment |
| Depth | Names one fix for everything | Names the complexity dial and the matching fix for each side | Explains why more data helps only some of the time |
| Trade-offs | None mentioned | Notes that cutting training error can raise validation error | Notes that tuning biases the validation score, so a test set stays untouched |
| Communication | Jargon without definitions | Plain definitions and one example | Diagnostic first, then fixes, in under a minute |
| Follow-up readiness | Stuck when asked how to tell | Can read a loss curve | Connects to bias and variance and to regularization |
Three variants of this question
How can you tell from a learning curve that a model overfits?
A learning curve plots training and validation scores against the number of training samples; a persistent gap with a high training score signals overfitting. The scikit-learn learning_curve function returns the numbers of samples used and the mean training and validation scores for exactly this plot (scikit-learn guide).
Can a model overfit when its training error is not zero?
Yes, because overfitting is about the gap and not about perfection. In the scikit-learn course's decision-tree validation curve, the model with a maximum depth of 10 overfits a bit because a gap opens between its training and validation scores (scikit-learn course). Unrepresentative training data can cause a gap too (Google).
What do you do when both the training and validation scores are poor?
Treat it as underfitting: make the model more flexible or give it better features, and do not expect more data to help a model that is too simple. The feature engineering guide covers the encoding and scaling choices that often matter first.
Common mistakes
- "A high training accuracy means a good model." (wrong) Training score says how well the model fits what it has seen. (right) "I report the validation or test score, because that is how the model does on unseen data."
- "Overfitting only happens with complex models." (wrong) Google lists unrepresentative training data as a cause too (Google). (right) "Overfitting comes from model complexity or from training data that does not represent the real cases."
- "More data always fixes it." (wrong) More data helps only when the true function is too complex for a lower-variance estimator (scikit-learn). (right) "More data reduces variance, but an underfit model needs more capacity, not more rows."
- "I tuned on the validation set, so its score is my final number." (wrong) After tuning, that score is biased. (right) "I report a test score from data I touched only once."
Follow-up questions
How do you prevent overfitting?
Lower the model's complexity, add regularization that penalizes complexity, and train on more representative data. Watch the validation loss during training, because it rising while training loss falls is the warning sign (Google). Early stopping means ending training when the validation loss starts rising, and k-fold cross-validation, which lets each of k parts take a turn as the held-back part, helps choose the complexity. For neural networks, add dropout, which randomly drops units during training (Srivastava et al., 2014), and data augmentation; chapter 7 of Goodfellow, Bengio and Courville (2016) covers early stopping, dataset augmentation and dropout. The regularization comparison covers the two common penalties.
How are overfitting and underfitting related to bias and variance?
High bias corresponds to underfitting and high variance to overfitting, a link the scikit-learn guide draws when it describes validation curves. The bias vs variance page gives the fuller decomposition.
Does more training data fix overfitting?
Only sometimes. It reduces the variance of a model, but the scikit-learn guide says to collect more data only if the true function is too complex for an estimator with lower variance (scikit-learn). Simplifying or regularizing the model is often faster.
If validation scores are good but production results are bad, is that overfitting?
Not necessarily. The cause can be training data that does not represent real traffic, or inputs that changed after training; see distribution shift for how to detect it.
What does the loss curve look like when a classifier overfits?
The training loss keeps declining or flattens while the validation loss starts to rise (Google). For a classifier the loss is usually cross-entropy loss.
- Underfitting is a model too simple to fit even its training data; overfitting is a model that learns noise and fails on new data.
- Compare the training score with the validation score: both low is underfitting, a high-low gap is overfitting.
- Model complexity is the dial between them, and the goal is the balanced middle.
- Fix underfitting with capacity or features; fix overfitting with simplicity, regularization or representative data.
- Keep a test set untouched, because tuning on the validation set biases its score.
Sources
- Underfitting vs. Overfitting (scikit-learn 1.9.1 example) — scikit-learn developers, 26 Oct 2026
- Validation curves: plotting scores to evaluate models (scikit-learn 1.9.1 user guide) — scikit-learn developers, 26 Oct 2026
- Validation curves and learning curves, guide source (scikit-learn repository) — scikit-learn developers (GitHub), 26 Oct 2026
- Overfitting - Machine Learning Crash Course — Google for Developers, 26 Oct 2026
- Overfitting: Model complexity - Machine Learning Crash Course — Google for Developers, 26 Oct 2026
- Overfit-generalization-underfit (scikit-learn MOOC) — Inria scikit-learn course, 26 Oct 2026
- Datasets, generalization, and overfitting - Machine Learning Crash Course — Google for Developers, 26 Oct 2026
- Regularization for Deep Learning (Deep Learning, chapter 7) — Goodfellow, Bengio and Courville (MIT Press), 18 Nov 2016
- Dropout: A Simple Way to Prevent Neural Networks from Overfitting — Journal of Machine Learning Research (Srivastava et al.), 1 Jun 2014
- Reconciling modern machine learning practice and the bias-variance trade-off (arXiv 1812.11118) — arXiv (Belkin et al.), 28 Dec 2018