</>
Vizly

The Bias-Variance Tradeoff

July 4, 20269 min
MLOverfittingModel Evaluation

Every model failure is one of two failures. Learn to tell them apart and you'll know exactly which knob to turn.

Two students, one exam

Picture two students preparing for the same exam.

The first one skims a summary sheet the night before. She learns that "revenue minus costs equals profit" and not much else. On exam day, she applies her one crude rule to every question. She gets the easy ones roughly right and everything else wrong. Ask her to retake the exam with different questions, and she'd score about the same. Consistently mediocre.

The second student memorizes every practice problem, word for word, including the typos. On any question copied from the practice set, he's perfect. On anything reworded, he falls apart, because he never learned the underlying ideas, he learned the exact sentences. Give him a different practice set to memorize and his exam answers change completely.

The first student has a bias problem. The second has a variance problem.

Every model you will ever train fails in one of these two ways, or some blend of both. Learning to diagnose which one you're looking at is arguably the most practical skill in all of machine learning.


What bias and variance actually mean

Let's make the intuition precise, using a fraud model as the running example.

Imagine you could retrain your model many times, each time on a fresh sample of transactions from the same source. Different customers, different weeks, same underlying reality. Each training run produces a slightly different model, which makes slightly different predictions.

Bias is how far the average of all those models lands from the truth. High bias means that even averaging over every possible training set, your model systematically misses. It's too simple to represent what's really going on. A fraud model that only looks at transaction amount has high bias: fraud depends on merchant, timing, device, velocity, and no amount of data fixes a model that can't see those things.

Variance is how much the models disagree with each other across those training sets. High variance means your model is exquisitely sensitive to which particular transactions it happened to see. Train on January's data, get one model. Train on February's, get a noticeably different one. The model is fitting the noise in each sample, not just the signal shared by all of them.

The dartboard version: bias is where your darts cluster relative to the bullseye, variance is how spread out they are.

Here's the punchline that gives the tradeoff its name: your model's expected error on new data breaks down, mathematically, into bias squared plus variance plus irreducible noise. Push one down and the other tends to creep up. The game is finding the balance point.

(The noise term is real, by the way. Some fraud is genuinely indistinguishable from legit behavior given the features you have. No model fixes that. Chasing error below the noise floor is how people end up overfitting.)


The complexity dial

What controls where you sit on this spectrum? Mostly one thing: model complexity, meaning how much flexibility the model has to bend itself around the training data.

Turn the dial to the left, toward simple models, and you get the summary-sheet student. A logistic regression with three features can't memorize anything, but it also can't capture interactions like "small transactions are fine except at 3am from a new device." Underfitting. High bias.

Turn the dial to the right, toward very flexible models, and you get the memorizer. A deep, unconstrained gradient-boosted ensemble can carve out a rule for practically every training example, including the ones that were flagged fraud by mistake. Overfitting. High variance.

As you sweep the dial from left to right, something characteristic happens:

Training error goes down, and keeps going down. More flexibility always fits the training set better.

Validation error goes down at first, bottoms out, then climbs back up. That U-shape is the bias-variance tradeoff drawn as a curve, and the bottom of the U is where you want to live.


How do you diagnose it in practice?

You will never compute bias and variance directly on a real project. What you have instead is two numbers you already track: training error and validation error. The gap between them is your diagnostic.

SymptomTrain errorValidation errorDiagnosis
Both bad, and close togetherHighHighHigh bias, underfitting
Train great, validation much worseLowHighHigh variance, overfitting
Both good, small gapLowLowYou're done, ship it

The reasoning is simple. Training error tells you whether the model can capture the pattern at all. If it can't even fit data it has already seen, it's too simple: bias. Validation error tells you whether what it learned transfers. A big train-validation gap means the model learned things specific to the training sample: variance.

Say your credit scoring model shows 2% error on training data and 11% on validation. That 9-point gap is screaming variance. The model has effectively memorized its training customers. Meanwhile a colleague's model shows 10% on both. No gap, but a high floor: that's bias, and their model needs more capacity or better features, not more constraints.

Two models, similar validation numbers, opposite problems, opposite fixes. This is why "what would you try next?" is such a common interview question. The answer depends entirely on which failure mode you're in.

The fixes are opposites

Almost every remedy helps one problem and worsens the other. More features, bigger models, longer training: good for bias, risky for variance. Regularization, simpler models, early stopping: good for variance, risky for bias. Applying a variance fix to a bias problem (or vice versa) makes your model worse. Diagnose first, then treat.


Regularization: the knob you'll actually turn

In practice, you rarely fix variance by throwing your model away and picking a simpler one. You keep the flexible model and penalize it for using its flexibility. That's regularization.

The idea fits in one sentence: add a term to the loss function that charges the model for large weights, so it only spends complexity where the data genuinely demands it.

# ordinary loss: fit the data, whatever it takes
loss = prediction_error
 
# regularized loss: fit the data, but complexity costs you
loss = prediction_error + lambda_ * sum(w**2 for w in weights)

That lambda_ is a dial from "do whatever you want" (zero) to "stay nearly flat" (huge). Sweep it and you're walking along the same U-shaped curve from earlier, just controlled by a single number you can tune against validation error. This is L2 regularization, known as ridge. Its sibling L1 (lasso) penalizes absolute weights instead and pushes weak feature weights all the way to zero, which is handy in fintech where you may need to explain to a regulator exactly which features drive a credit decision.

Regularization wears a lot of costumes, and it's worth recognizing them as the same trick: tree depth limits and pruning in XGBoost, dropout in neural networks, early stopping during training. Different mechanics, one purpose. Restrain the memorizer.


Why more data fixes one problem but not the other

Here's a question that separates people who've internalized this from people who've memorized definitions. Your model is struggling. Someone suggests collecting more training data. Will it help?

It depends entirely on your diagnosis.

More data attacks variance. Variance is sensitivity to the particular sample you trained on. Quirks and noise differ from sample to sample, so with more data, they average out and the real signal, which is present in all of it, dominates. The memorizing student can't memorize a million practice problems. Forced to compress, he finally starts learning patterns. In practice, the train-validation gap shrinks as data grows.

More data does nothing for bias. If your model is a straight line and the true pattern curves, ten billion points will only make it more precisely, confidently wrong. The summary-sheet student doesn't improve if you hand her a thicker stack of exams to apply her one rule to. Her problem isn't information, it's capacity.

So before your team spends a quarter building pipelines to ingest more transaction history, look at the error table. Big train-validation gap? The data will pay off. Both errors high and close together? Spend the quarter on features and model capacity instead. That one diagnostic can save months.

A cheap experiment before an expensive one

Plot your validation error as a function of training set size (train on 10%, 25%, 50%, 100% of what you have). If the curve is still falling at 100%, more data will likely help. If it flattened long ago, you've hit a bias wall and more data is wasted money. This learning-curve trick takes an afternoon and can redirect an entire roadmap.


The series, in one breath

This wraps up Statistics and Probability. Look how the pieces connect: probability gave you the language of uncertainty, distributions described how data behaves, Bayes taught you to update beliefs with evidence, sampling explained why your data is a noisy window on reality, hypothesis testing told you when a difference is real, MLE showed where loss functions come from, and bias-variance explains how the whole enterprise fails and how to fix it.

That's the statistical backbone of every ML system you'll build or be interviewed on.

Next up in the ML Engineer path: Essence of Linear Algebra. Every model we've discussed stores what it learns as vectors and matrices, and training is just arithmetic on them. Time to look at the math running under every model's hood, and I promise it's more visual and less scary than you remember from university.

Edit this page on GitHubโ†—