# Overfitting vs Underfitting

> Overfitting vs underfitting: what each one looks like, how to spot it with two scores, and how to fix it, for your AI interview.

**In short:** Overfitting is when a model memorises its training data, noise included, so it fails on new data. Underfitting is when a model is too simple to learn the pattern, so it fails even on the data it trained on.

AI and LLM interview question Q413, Classic ML and deep-learning basics. Beginner, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/overfitting-vs-underfitting

## Say it in 30 seconds

Overfitting means a model learned its training examples too closely, random quirks included, so it looks great on old data and poor on new data. Underfitting means the model is too simple to learn the pattern, so it is weak on both. I spot the difference by comparing two scores: the training score and the check set score. A big gap points to overfitting. Low on both points to underfitting. The fixes pull in opposite directions, so I never fix one by reflex.

## Say it in 2 minutes

Every model is built from examples it has seen, and the real test is how it does on examples it has not seen. Overfitting and underfitting are the two common ways a model fails that test. Both come down to how well the model learned the real pattern.

Overfitting means the model learned its training data so closely, random quirks included, that it breaks on new cases. Underfitting means the model is too simple to learn the pattern at all, so it is weak even on the data it trained on. To tell them apart, I compare two scores. A big gap, with a high training score and a low check score, points to overfitting. Low scores on both point to underfitting.

The fixes pull in opposite directions. For overfitting I add more varied examples, limit complexity with regularisation, a penalty that keeps the rules simple, and stop training when the check score stops improving. For underfitting I give the model inputs that really predict the outcome, or a model with more room to learn. Adding complexity helps one problem and makes the other worse, so I change one thing at a time and re-check.

Take a bank's loan model. It scores 99 percent on last year's files and 71 percent on this month's applicants. That gap is the warning sign. I would first check that the check set was really held back, then compare with a simpler model, then retrain on recent cases before trusting any new score.

## What are overfitting and underfitting, in plain words?

An AI model learns patterns from examples, then has to work on cases it has never seen. Overfitting and underfitting are two common ways that goes wrong. Both describe how well the model learned the real pattern.

Think of a new credit analyst at a bank who studies last year's loan files. The first analyst memorises every file, names and exact amounts included. Give them a new applicant and they freeze, because nothing matches word for word. That is overfitting. The second analyst learns one rule, that big loans are risky, and gets even the old files wrong. That is underfitting.

AI works the same way. A bank trains a model on last year's loan files to flag applicants likely to default, which means stop repaying. A model that memorised those files misses new kinds of risk. A model with one rule misses risk even in the old files. What the bank wants is a model that generalises, meaning it does well on applicants it never learned from.

- **Training data:** The examples the model learns from.
- **Check set:** Examples held back to check the model while you tune it. Also called validation data.
- **Generalise:** Do well on new data the model never learned from.
- **Noise:** Random quirks in the data that will not repeat in new data.

## How do you tell which one a model has?

Compare two scores: how the model does on its training data, and how it does on a check set it never trained on. The gap between them, and whether both are low, tells you which problem you have. The table uses made-up numbers from a loan model, on a balanced sample of half defaults and half repayments. Old means the training files the model learned from. New means the check set it never saw.

- **Underfitting: 66% old, 64% new.** Weak on both. The model is too simple, so it misses the pattern even in the files it learned from.
- **Overfitting: 99% old, 71% new.** A 28-point gap. The model memorised last year's files, so it falls apart on new applicants.
- **Good fit: 88% old, 85% new.** Both scores high and close. It learned the pattern, and it holds up on new applicants.

scikit-learn's official example makes the same points. A straight line that cannot fit the training points is underfitting. A high training score with a low check score is overfitting.

*Diagram, Where a model can land: All three start from one model choice. Too little room leaves the model weak everywhere. Too much room lets it memorise random quirks, so only the old files look good. Both need adjusting, and the check score tells you when the adjustment worked.*
1. Too little room to learn the pattern.
2. So much room that it learns every quirk.
3. It stays weak on the training files too.
4. Its old-file score is high and its new-file score low.
5. Both scores are low, so it needs more to work with.
6. The gap says to limit complexity and add data.
7. Re-check: the two scores move close and high.

> "Overfitting means creating a model that matches (memorizes) the training set so closely that the model fails to make correct predictions on new data." (Google's machine learning course)
>
> "An underfit model doesn't even make good predictions on the training data." (Google's machine learning course)
>
> "However, for higher degrees the model will overfit the training data, i.e. it learns the noise of the training data." (scikit-learn)

## What do you do about each one?

Overfitting comes from causes such as unrepresentative training data and overly complex models. The fixes point in opposite directions, so never fix a model by reflex. Adding complexity helps underfitting and makes overfitting worse.

*Diagram, Fixes depend on the symptom: Underfitting needs the model to see the pattern: better inputs or more room to learn. Overfitting needs it to ignore noise: more varied data, simpler rules and an early stop. Both are done when the training and check scores come out close and high.*
1. Give it better inputs or more room, then re-score.
2. Use more varied cases, simpler rules and an early stop, then re-score.

1. **Check the split first:** Make sure the check set was really held back and looks like the cases the model will face. If some check cases also sat in the training files, every score looks better than it is.
2. **Add more varied examples:** Cases from more months, branches and customer types make it harder to memorise one year's quirks.
3. **Limit complexity:** Regularisation adds a cost for extra complexity, so the model keeps simpler rules. Google's course says a simpler model often generalises better on new data.
4. **Stop training early:** Stop when the check score stops improving, before the model starts memorising. Watch the gap between the two scores.
5. **Give underfitting models more to work with:** Add inputs that really predict default, such as income stability and repayment history, or use a model with more room to learn.

### How would you handle a loan model that is right on old files but not new ones?

Your team has shipped a loan model. It scored 99 percent on last year's files and 71 percent on this month's applicants. What do you do first?

1. **Check the gap is real:** Confirm the check set was held back and matches this month's applicants. If some check cases also sat in the training files, the check score is inflated and the real gap may be wider. Defaults can take months to show, and a shift in who applies can open a gap too.
2. **Compare with a simpler model:** If a simpler model does nearly as well on new applicants, the complex one is probably memorising. Keep the simpler one.
3. **Retrain on recent cases:** Add the last few months of applicants, including new kinds of risk, and keep a test set from the newest months.
4. **Re-check before trusting it:** Measure the gap again on fresh data. Only a small gap and a good score earn the model a place back in use.

I would not keep adding complexity to lift the old score. That only widens the gap.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a model that memorises its training data, or one too simple to learn it.
- [ ] The two-score check: training score against a check set it never saw.
- [ ] A big gap means overfitting. Low on both means underfitting.
- [ ] The fixes conflict: more complexity helps one and hurts the other.
- [ ] Fixes for each: varied data, simpler rules and early stopping for overfitting; better inputs and more room to learn for underfitting.
- [ ] Honest testing: tune on the check set, then score a final test set you never tuned on.

**Common traps**

- Trap: "A model that scores 99 percent is the best one." Better: A high training score alone proves little. Check the score on new data before trusting it.
- Trap: "More complexity always gives a more accurate model." Better: Past a point, extra complexity memorises noise. Watch the gap between the two scores.
- Trap: "Tune the model until the check score is highest." Better: Tuning against the check set makes that score biased, as scikit-learn notes. Keep a separate final test set.

## Can you spot the overfitting?

**Spot the overfitting:** A churn model at a phone company shows these scores on two samples. Which row shows overfitting?

A. Training 62%, check 60%. Both are weak.
B. Training 97%, check 74%. The gap is 23 points.
C. Training 88%, check 87%. The scores are close.
D. Training 55%, check 58%. Both are low and close.

**Answer:** B. A high training score with a much lower check score is the overfitting pattern: the model learned its old customers too closely. Low on both is underfitting, and close scores are a good sign.

**Quick check:** Your loan model scores 99 percent on training data and 71 percent on the check set. What do you change first?

A. Train it for longer on the same files
B. Add more varied applicants and cap the complexity
C. Drop the check set so the model sees everything
D. Switch to a deeper model with more rules

**Answer:** B. The gap says the model memorised its training files. More varied cases and a limit on complexity push it to learn the pattern. Training longer or going deeper makes memorising easier, and dropping the check set hides the problem.

## Can you answer these from memory?

**Flash cards**

- **What is overfitting?** The model memorises its training data, noise included, and fails on new data.
- **What is underfitting?** The model is too simple to learn the pattern, so it is weak even on training data.
- **Which two scores do you compare?** The training score and the score on a check set it never trained on.
- **Big gap between the two scores?** Overfitting: the model memorised its training data.
- **Low on both scores?** Underfitting: the model needs more room to learn or better inputs.
- **Do the fixes agree?** No. More complexity helps underfitting and makes overfitting worse.

## Likely follow-up questions

- Q412 Bias vs variance? https://designervenkat.online/interview/ai/bias-vs-variance
- Q414 L1, L2 and dropout regularisation? https://designervenkat.online/interview/ai/l1-l2-and-dropout-regularisation
- Q422 Train/validation/test splits? https://designervenkat.online/interview/ai/train-validation-test-splits
- Q423 What is cross-validation? (full answer coming)
- Q424 What is data leakage? (full answer coming)
- Q297 How do you spot overfitting during fine-tuning? https://designervenkat.online/interview/ai/how-do-you-spot-overfitting-during-fine-tuning
