# Bias vs Variance

> What bias and variance mean, how each one causes errors on new data, and how to tell them apart and fix each, for your AI interview.

**In short:** Bias is error from a model that is too simple to learn the real pattern. Variance is error from a model so sensitive to its training data that its predictions swing when the data changes. Good models keep both low.

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

## Say it in 30 seconds

Bias is error from a model that is too simple to learn the real pattern. Variance is error from a model that is too sensitive to its training data, so its answers swing when the data changes. In a loan-risk model I'd check both scores: if both are poor, that's usually bias; if training is great and new data is poor, that's variance. The fixes are different, so I diagnose before I change anything.

## Say it in 2 minutes

Every model makes errors on new data. Two of the causes you can act on are bias and variance. Bias is the error that comes from wrong assumptions. If a model is too simple, like a straight line for a curved pattern, it misses the real trend every time, however much data it sees. Variance is the error that comes from sensitivity. If a model is too flexible, it learns the quirks of one training set, and its predictions swing when it is trained on another sample of the same problem.

Think of a new claims assessor at an insurer. One follows a rigid checklist and misses anything the checklist was never built to catch, which is bias. Another memorises last month's claims and freezes at anything new, which is variance. In a real team the signs show in the scores. If both the training and the validation scores are poor, the model is underfitting, which points to bias. If training is excellent and validation is much worse, the model is overfitting, which points to variance.

The fixes differ. For bias, use a richer model or better features. For variance, get more data, add a penalty on complexity, or simplify the model. Averaging many models trained on different samples, which is called bagging, is a known way to cut variance at a small cost in bias. Most real work is finding the setting where the total error is lowest.

One caution: very large modern models can improve again past the point where they fit every training example, a pattern researchers call double descent. Treat the classic balance as the everyday rule, and check the scores rather than trusting the theory alone.

## What are bias and variance, in plain words?

Every model makes errors on new data. For squared error, which is typical for regression, the scikit-learn library, a standard Python toolkit for machine learning, splits that error into three parts: bias, variance and noise.

Bias is error from wrong assumptions. Variance is error from being too sensitive to the training data. Noise is random variation in the data itself, which no model can remove.

Picture a new claims assessor at an insurer. One follows a rigid checklist, so they miss anything the checklist was never built to catch. That is bias. Another memorises last month's claims and freezes at anything new. That is variance. Both get new claims wrong, for different reasons.

The same two problems hit AI models. A loan-risk model at a mid-size bank can be too simple to spot risky applicants, or so tuned to its training loans that it fails on loans it has not seen.

- **Bias:** Error from a model that is too simple or has the wrong assumptions, so it misses the real pattern.
- **Variance:** Error from a model so sensitive to its training data that its predictions swing when the data changes.
- **Noise:** Random variation in the data itself. No model can predict it.
- **Underfitting:** The model is too simple and does badly even on the data it learned from.
- **Overfitting:** The model learns its training data too closely, quirks included, and does badly on new data.

## What does high bias look like, and high variance?

Take the loan-risk model. Plot each applicant's debt ratio against their true risk, and the pattern is a gentle curve. A straight line is too simple for that curve, so the model underfits. It does badly even on the loans it trained on, which is why scikit-learn's guide calls it high bias.

A very wiggly curve does the opposite. It passes through every past loan, then drifts badly on new applicants. Scikit-learn's underfitting example says that, for higher degrees, the model overfits: it learns the noise in the training data.

*Diagram, Loan risk, three models: The same loan-risk curve, fitted three ways, left to right. Each step adds flexibility. The straight line misses the trend, the gentle curve follows it, and the wiggly curve follows the noise too. The middle one is the balance to look for.*
1. More flexibility lets the model follow the real trend, so bias falls.
2. Too much flexibility makes it follow the noise, so variance grows.

- **High bias: Bad on training data too.** The model never learns the pattern, so both of its scores are poor.
- **High variance: Great on training, poor on new.** The model memorised its training set. Its score drops sharply on data it has not seen.
- **Healthy: Close scores, both good.** Training and new-data scores are close and high. This is the target.

Google defines overfitting, the usual sign of high variance, and scikit-learn defines high variance directly.

> "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 machine learning course)
>
> "it is very sensitive to varying training data (high variance)" (Scikit-learn validation curves guide (section 3.5))

## How do you tell which problem you have?

Hold back some data the model never trained on. This is the validation set. Then compare two scores: the training score and the validation score.

If the two sets come from different periods, the world may have changed. That is a data problem, and you should check that the new data matches the training data first.

Scikit-learn's learning curve is a common tool for this. It shows both scores as the training set grows, so you can see whether the model suffers more from variance or from bias.

Here is a worked example with made-up numbers. A mid-size bank trains a model to flag small-business loans that may default. Three attempts look like this:

1. **Both scores low:** Training 71%, new data 70%, measured as recall (the share of real defaults it flags). The model cannot learn even its own training loans. That usually means high bias: add better features or a richer model, unless the data is so noisy that no model could do much better.
2. **Training high, new data low:** Training 99%, new data 78%, both measured as recall. It may have memorised the training loans. That usually means high variance: add more loans, add a penalty, or simplify.
3. **Both scores high and close:** Training 84%, new data 83%, both measured as recall. The gap is small and the level is good. Check it on a later month of loans before you ship.

> **Tip:** Asked what to do next? Check the scores before you ask for more data. Scikit-learn's learning curve guide makes the point with a naive Bayes example: when both scores settle low, more training data helps little.

## How do you reduce bias and variance?

The fixes pull in opposite directions, which is why this is called a trade-off. More flexibility lowers bias and raises variance. Less flexibility does the reverse, so the job is finding the balance point. A penalty is one way to get there: the training step charges the model for extra complexity, so it prefers simpler settings.

*Diagram, Which fix for which problem: Each problem has its own fix. More detail reduces bias, while more data or a penalty reduces variance. Both paths aim at the lowest total error the model can reach.*
1. High bias is treated with more detail, so both scores rise.
2. High variance is treated with more data or a penalty, so the gap closes.
3. A richer model cuts the bias part of the error.
4. More data or a penalty cuts the variance part of the error.

Averaging is another classic fix for variance. Scikit-learn's bagging example averages many trees trained on different samples, and it measures the effect directly. The first card is that example. The second is the paper behind the exception below.

> "averaging several decision trees fit on bootstrap copies of the dataset slightly increases the bias term but allows for a larger reduction of the variance" (Scikit-learn bagging example)
>
> "The bias-variance trade-off implies that a model should balance under-fitting and over-fitting" (Belkin and colleagues, arXiv paper)

The classic U-shaped curve has an exception. Belkin and colleagues found that very large modern models can get better again past the point of fitting every training example (researchers call that point interpolation), a pattern they call double descent. Treat the balance as the everyday rule, and check the scores.

Here is a small, made-up check in plain Python. It draws 300 random training sets of 30 customers from one loan pattern, then asks two models for the same new applicant. The flat average misses the true risk and barely moves, which is high bias. The nearest-customer copier lands near it on average but jumps around, which is high variance.

```python
# A made-up loan-risk pattern: the true risk rises with the applicant's debt ratio (x from 0 to 1).
# Each model sees 300 random training sets of 30 customers, then predicts for the same new applicant.
import random
import statistics

def true_risk(x):
    return 0.2 + 0.5 * x

def sample(rng, n):
    xs = [rng.random() for _ in range(n)]
    return [(x, true_risk(x) + rng.gauss(0, 0.1)) for x in xs]

def fit_flat(data):
    # Too simple: always predicts the average risk of its training customers.
    avg = statistics.fmean(y for _, y in data)
    return lambda x: avg

def fit_nearest(data):
    # Too flexible: copies the closest training customer.
    return lambda x: min(data, key=lambda p: abs(p[0] - x))[1]

rng = random.Random(7)
new_applicant = 0.8
for name, fit in [("flat average", fit_flat), ("nearest customer", fit_nearest)]:
    preds = [fit(sample(rng, 30))(new_applicant) for _ in range(300)]
    bias = statistics.fmean(preds) - true_risk(new_applicant)
    spread = statistics.pstdev(preds)
    print(f"{name}: bias {bias:+.3f}, spread {spread:.3f}")
```

Output:

```text
flat average: bias -0.149, spread 0.035
nearest customer: bias +0.003, spread 0.095
```

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: bias is error from a model too simple for the pattern; variance is error from one too sensitive to its data.
- [ ] Both sit inside the error on new data, next to noise.
- [ ] Diagnose with the two scores: both poor usually means bias, a big gap usually means variance.
- [ ] The fixes differ: a richer model for bias; more data, a penalty or averaging for variance.
- [ ] The trade-off: more flexibility lowers bias and raises variance, so you look for the balance point.
- [ ] An honest exception: very large modern models can improve again (double descent).

**Common traps**

- Trap: "More data always fixes it." Better: More data mainly reduces variance. A model that is too simple stays too simple however many rows you add.
- Trap: "Lower training error means a better model." Better: Training error can fall while new-data error rises. Judge the model on data it has not seen.
- Trap: "Bias is always bad, so use the most complex model." Better: Some bias buys stable predictions. The aim is the lowest total error, which usually means accepting a little bias.

## Can you spot the problem?

**Spot the problem:** A claims-triage model scores 98% on its training claims and 71% on a held-out set of claims from the same months. Which review note is right?

A. Scores are close, so the model is ready for production.
B. The gap is large: the model memorised its training claims, which is high variance.
C. Both scores are low, so the model is too flexible.
D. Add a deeper network, because the model is underfitting.

**Answer:** B. A big gap between training and new-data scores usually points to variance. Two low, close scores would point to bias, and that is not what this review shows.

**Quick check:** A linear model for card fraud, scored by recall (the share of real fraud it catches), gets 62% on training data and 61% on new data. What is the most likely fix?

A. Collect more examples of the same kind
B. Use a richer model or better features
C. Add a much stronger penalty on complexity
D. Stop training earlier

**Answer:** B. Both scores are low and close, so the model is too simple: that is high bias. A richer model or better features gives it the detail it needs. More data and penalties mainly help variance, which is not the problem here.

## Can you answer these from memory?

**Flash cards**

- **What is bias?** Error from a model that is too simple or has wrong assumptions, so it misses the pattern.
- **What is variance?** Error from a model so sensitive to its training data that its predictions swing.
- **Signs of high bias?** Usually, training and new-data scores are both poor and close together.
- **Signs of high variance?** Training score is high, and the new-data score is much lower.
- **Fixes for high variance?** More data, a penalty on complexity, a simpler model, or averaging many models.
- **Is there a catch?** Yes. Lowering bias usually raises variance, so you look for the balance point.

## Likely follow-up questions

- Q413 Overfitting vs underfitting? https://designervenkat.online/interview/ai/overfitting-vs-underfitting
- Q414 L1, L2 and dropout regularisation? https://designervenkat.online/interview/ai/l1-l2-and-dropout-regularisation
- Q417 What does the learning rate do? (full answer coming)
- Q415 What is gradient descent? https://designervenkat.online/interview/ai/what-is-gradient-descent
- Q422 Train/validation/test splits? https://designervenkat.online/interview/ai/train-validation-test-splits

## Learn it in depth

- [Model evaluation: is it any good?](https://designervenkat.online/learn/machine-learning/model-evaluation)
