Machine Learning Slides 📂 Introduction · 7 of 17 63 min read

Bias, Variance, Underfitting & Overfitting

A visual, beginner-friendly guide to the bias-variance tradeoff and its two failure modes — underfitting and overfitting. Learn the dartboard analogy, the error decomposition (Bias² + Variance + Noise), the U-shaped complexity curve, how to diagnose problems using learning curves, targeted fixes for each side (regularisation, more data, ensembles), and six golden rules every ML practitioner should follow.

🎯

Bias · Variance · Overfitting

The four failure modes every ML model can land in — and the U-curve that quietly rules every training run you'll ever launch. From dartboard intuition to gradient-boosting cures.
The Dartboard The U-Curve Diagnose · Fix Regularise · Ensemble

Press Next → or use ← → arrow keys

Section 01

Four Words Every ML Practitioner Must Own

Coach Arjun's archers — Priya vs Ravi
Priya shoots five arrows and every one lands in the top-left corner — consistent, but consistently wrong. That's high bias.

Ravi shoots five arrows and they land everywhere — one bullseye, one in the sky, three in different corners. Sometimes right, always unpredictable. That's high variance.

A good model is like the archer whose arrows cluster tightly around the bullseye — low bias, low variance. Everything that follows is how to become that archer.
🎯
Bias
systematic error
How far off is the model on average? High bias = the model is too simple to capture the pattern.
🌀
Variance
sensitivity to data
How much does the model change if we retrain on a different sample? High variance = memorising noise.
Good Fit
the sweet spot
Low bias AND low variance. Captures the real pattern without chasing the noise. Both errors small.
Section 02

The Dartboard — Four Ways A Model Can Fail

LOW VARIANCE HIGH VARIANCE LOW BIAS HIGH BIAS ✅ THE GOAL OVERFITTING UNDERFITTING WORST CASE
🎯
Each Dart = One Model Trained On One Random Split

Cluster location reveals bias (are the darts near the bullseye?). Cluster spread reveals variance (how tightly do they group?). Every model you train lives somewhere on this board — your job is to move it toward the top-left.

Section 03

Underfit vs Good Fit vs Overfit — In Pictures

UNDERFIT too simple · high bias train ✗ test ✗ GOOD FIT captures pattern · ignores noise train ✓ test ✓ OVERFIT memorises noise · high variance train ✓✓ test ✗
ModelTrain ErrorTest ErrorGapVerdict
Straight line (deg 1)4442smallHigh Bias · Underfit
Smooth curve (deg 3)1013smallSweet Spot ✅
Wiggle (deg 15)0.275HUGEHigh Variance · Overfit
Section 04 · Interactive

🎬 Feel The Bias — Cycle Through Complexities

Hold the data fixed. Click Next Model to increase complexity from a flat line all the way to a degree-15 wiggle. Watch the green curve pull closer to the true trend — that shrinking gap is bias decreasing in real time.

Model Complexity 1 / 5

Constant Model degree 0 · flat line

x (feature) → — true trend
Bias: · Variance: · Train MSE:
▶ Press Next Model to increase complexity and watch bias fall — until variance takes over at the extreme.
Section 04

The One Equation Ruling Every Model

Total Prediction Error
Error(x) = Bias² + Variance + Irreducible Noise
Every ML error decomposes into these three parts. Two you can influence. One you cannot.
Bias & Variance
Bias = E[ŷ] − y · Var = E[(ŷ − E[ŷ])²]
Bias = how far off on average. Variance = how much the prediction wiggles across retrainings.
🎯
Bias²
controllable
Wrong assumptions in the model. Fix: more complex model, more features, less regularisation.
🌀
Variance
controllable
Fitting training noise. Fix: more data, regularisation, simpler model, ensembles.
🌫️
Irreducible Noise
the floor
Randomness intrinsic to the data. No model can beat it. Don't waste compute trying.
🚫
Do Not Chase The Noise Floor

If irreducible noise is 8%, your best possible test error is 8%. Any model achieving 2% train error on such data has memorised, not learned. Accept the floor.

Section 05

The U-Curve — Complexity's Two-Sided Cost

Model Complexity → Error → Bias² Variance Total Error SWEET SPOT optimal complexity ← underfit overfit →
⚖️
You Cannot Reduce Both By Complexity Alone

Moving right along the complexity axis always trades bias for variance. The only ways out of the tradeoff: more data (curve flattens), regularisation (curve shifts), ensembles (average many models). Everything else is picking a point.

Section 06 · Interactive

🎬 Feel The Variance — Cycle Through Data Samples

Two models — simple linear vs complex deg-15 — trained on the same underlying pattern. Click Next Sample to reshuffle the noise. The blue line barely twitches (low variance). The purple curve reinvents itself completely (high variance).

Data Sample 1 / 4

Simple Model linear · low complexity

x (feature) → — true trend
Train MSE: · Line hardly moves across samples

Complex Model deg 15 · high complexity

x (feature) → — true trend
Train MSE: · Curve twists to hit every dot
▶ Press Next Sample to shuffle the noise. Compare how each model reacts.
Section 07

Learning Curves — Your One-Chart Diagnostic

HIGH BIAS both curves converge to high error more data won't help GOOD FIT small gap · both low healthy · ship it HIGH VARIANCE large train–val gap more data will close gap train error validation error
📉
Read The Chart Before You Touch A Hyperparameter

Both curves high, small gap → underfitting: add complexity or features. Both curves low, small gap → ship the model. Train low, val high, huge gap → overfitting: regularise, get more data, or simplify.

Section 08

The Fix Map — Diagnose First, Then Cure

🎯 UNDERFITTING high bias · both errors bad "model too simple" ➕ Add features / interactions 🧠 Increase model complexity 🎚️ Reduce regularisation (λ ↓) 🌀 OVERFITTING high variance · huge gap "memorises noise" 📊 Collect more data 🎚️ Increase regularisation (L1/L2) ⏹ Early stopping · dropout 📉 Simplify model / prune 🧺 Bagging (Random Forest) Note — MORE DATA: ✗ won't fix bias ✓ shrinks variance
🩺
Diagnose Before You Prescribe

Throwing "more data" at high bias fails. Throwing "more complexity" at high variance backfires. Plot the learning curve first, then pick a remedy from the matching column.

Section 09

Regularisation — Sliding Along The Curve

L2 · Ridge
J(β) = Loss + λ · Σ βⱼ²
Shrinks all weights proportionally toward zero. Keeps every feature — smaller coefficients.
L1 · Lasso
J(β) = Loss + λ · Σ |βⱼ|
Pushes some weights to exactly zero → automatic feature selection. Sparse model.
λ valueEffectSymptom
λ = 0No constraint · full complexityHigh variance · overfitting risk
λ small (0.001–0.1)Mild constraint · balancedSweet spot for most datasets
λ moderate (1–10)Meaningful shrinkageGood for noisy or wide feature sets
λ large (100+)Weights crushed toward zeroHigh bias · underfitting risk
🔍
Tune λ On A Log Grid, Via Cross-Validation

Standard grid: [0.0001, 0.001, 0.01, 0.1, 1, 10, 100]. Use RidgeCV / LogisticRegressionCV / GridSearchCV — never eyeball λ. Regularisation is the steering wheel of the bias-variance curve.

Section 10

Ensembles — The Pragmatic Escape Route

🧺
Bagging
reduces variance
Train many high-variance models on bootstrap samples → average predictions. Individual wiggles cancel. Example: Random Forest.
🚀
Boosting
reduces bias
Train weak learners sequentially, each fixing the last one's errors. Example: XGBoost, LightGBM, CatBoost.
🥞
Stacking
reduces both
Train a meta-model on top of diverse base learners. Best-of-both when compute allows.
🧠
Why Ensembles Escape The U-Curve

A single model must pick one complexity level along the U. Ensembles combine many models with different biases/variances — the average lands lower than any single model can. This is why gradient-boosted trees still dominate tabular ML competitions.

Section 11

Implementation — Plot The Curve, Tune The λ

# ── Learning curves — diagnose bias vs variance ──
from sklearn.model_selection import learning_curve
from sklearn.linear_model import Ridge

sizes, train_err, val_err = learning_curve(
    Ridge(alpha=1.0), X, y,
    train_sizes=np.linspace(0.1, 1.0, 10),
    cv=5, scoring='neg_mean_squared_error', n_jobs=-1,
)
# Plot mean of train_err and val_err vs sizes — read the pattern.

# ── Validation curve — sweep complexity/regularisation ──
from sklearn.model_selection import validation_curve

train_err, val_err = validation_curve(
    Ridge(), X, y,
    param_name='alpha',
    param_range=np.logspace(-4, 3, 8),   # log grid — always
    cv=5, scoring='neg_mean_squared_error',
)

# ── Auto-pick λ with cross-validation ──
from sklearn.linear_model import RidgeCV

model = RidgeCV(alphas=np.logspace(-4, 3, 8), cv=5)
model.fit(X_train, y_train)
print(f"Best alpha: {model.alpha_}")
📈
Two Charts, Every Project

A learning curve (error vs training-set size) diagnoses bias vs variance. A validation curve (error vs a hyperparameter like λ or max_depth) picks the sweet spot. Both are one-liners in sklearn — no excuse to skip them.

Section 12

Common Pitfalls — What Silently Breaks Models

📊
Zero Train Error
the memorisation tell
Real data always has noise. Train MSE = 0 means memorisation, target leakage, or a broken split — never celebration.
🌊
More Data For Bias
wrong medicine
Collecting 10× more data won't rescue a linear model on cubic patterns. Diagnose first — more data cures variance, not bias.
🎚️
Eyeballing λ
"try 0.1 and see"
Regularisation strength must be picked via cross-validation on a log grid — never by intuition or a single value.
🔍
Ignoring Learning Curves
blind tuning
Tweaking hyperparameters without plotting curves = random walking. Plot first, tune second.
🎯
Chasing The Noise Floor
diminishing returns
If irreducible noise ≈ 8%, no model beats 8%. Adding complexity past the sweet spot only adds variance.
📉
Single-Split Verdict
variance blindness
One test-set score can't reveal variance. Report cross-val mean ± std. High std = high variance.
Section 13 · Part 1

Golden Rules — 1 to 3

🎯 BIAS · VARIANCE DISCIPLINE · RULES 1–3
1
Always plot learning curves before tuning hyperparameters. The curve tells you in seconds whether you have a bias problem or a variance problem — and every remedy depends on that answer.
2
Training error diagnoses bias · train–test gap diagnoses variance. High train error → high bias. Low train, high test → high variance. Never evaluate on test error alone.
3
More data cures variance, not bias. Doubling the dataset stabilises a wiggly model. It cannot rescue an oversimplified one — for bias, add complexity or features.
Section 13 · Part 2

Golden Rules — 4 to 6

🎯 BIAS · VARIANCE DISCIPLINE · RULES 4–6
4
Train error ≈ 0 is a red flag, not a trophy. Real data has noise. Zero training error means memorisation, target leakage, or a broken split. Investigate before shipping.
5
Regularisation moves you along the U-curve — use cross-validation to find the bottom. Sweep λ on a log grid via RidgeCV / GridSearchCV. Never pick a single value from intuition.
6
Ensembles are the most practical bias-variance manager. Bagging (Random Forest) crushes variance. Boosting (XGBoost) crushes bias. A properly tuned ensemble almost always beats a single model on tabular data.
The Bias-Variance Checklist

✅ Learning curve plotted · ✅ Bias vs variance diagnosed · ✅ Remedy matches diagnosis ✅ λ chosen by CV on log grid · ✅ Ensemble considered · ✅ Std reported alongside mean.

FINAL

Bias · Variance — The Landscape, Not A Problem

B² + V+ noise · the decomposition
UThe complexity curve
4Dartboard quadrants
3Learning-curve patterns
L1 · L2Regularisation steering wheel
6Golden rules
🎯
The Foundation Is Set

You now read the dartboard, the U-curve, and the learning-curve trio. You know which lever to pull for bias vs variance, and why ensembles cheat the tradeoff. Every model you tune from now on — linear, tree, or neural — lives inside this framework.

📚
Where To Go Next

Study cross-validation (to measure variance rigorously), then Ridge, Lasso & ElasticNet in depth, then Random Forest & XGBoost. Practise on Kaggle's House Prices — the same dataset a linear, a tree and an ensemble will land in three different spots on the U-curve.

🎯 End of tutorial · Press to review, or click Restart