Skip to main content
LearnMLAcademy
Intermediate10 min read

Bias-Variance Tradeoff

Diagnose bias-variance tradeoff, generalization error, and tradeoffs, with Python code, architecture diagrams, worked examples, and interview quiz.

What you will master in this lesson
Intuitive core mechanisms & practical real-world intuition
Step-by-step mathematical breakdown & visual diagrams
Runnable Python implementation & practical trade-offs

Bias-Variance Tradeoff

The Bias-Variance Tradeoff is a core idea in machine learning. It helps us understand why a model can be too simple, too sensitive to its training data, or balanced enough to work well on new data.

Bias-Variance in Simple Words

Imagine three students preparing for the same exam. One studies too little, one memorizes only the exact practice questions, and one understands the concepts. Machine-learning models can behave in a similar way.

Too Simple

Misses important patterns.

High Bias → Underfitting

Balanced

Learns the useful pattern without chasing every detail.

Good Generalization

Too Sensitive

Fits small details and noise in the training data.

High Variance → Overfitting
ModelTraining DataNew DataLikely Problem
Too simplePoorPoorHigh bias / underfitting
BalancedGoodGoodGood generalization
Too complexVery goodCan be much worseHigh variance / overfitting
Figure 5 — Bias-Variance Tradeoff: Target Analogy

High Bias (Underfitting)

Consistently off-target

High Variance (Overfitting)

Scattered, inconsistent

Low Bias & Low Variance

Ideal: accurate & consistent

Each coloured dot represents a model prediction · Bullseye = true target value

Understanding this concept helps answer critical questions like:

  • Why do some models overfit?
  • Why do some models underfit?
  • How do we improve prediction accuracy?
  • Why does model complexity matter?
  • How do regularization techniques work?

The Bias-Variance Tradeoff explains the balance between:

Learning too littlevsLearning too much

This balance determines how well a machine learning model performs on unseen data.


Real-World Intuition

Imagine a student preparing for exams.

Case 1 — Student Studies Very Little

High Bias

The student:

  • Does not understand concepts
  • Makes many mistakes
  • Performs poorly everywhere

Case 2 — Student Memorizes Entire Book

High Variance

The student:

  • Memorizes exact questions
  • Cannot handle new questions
  • Panics when pattern changes

Case 3 — Balanced Understanding

Good Generalization

The student:

  • Understands concepts
  • Solves unseen problems
  • Performs consistently

This student analogy is not a mathematical definition, but it gives a useful first picture of underfitting, overfitting, and generalization.


What is Bias?

In simple terms, high bias means the model makes assumptions that are too simple to capture an important pattern in the data.

A high-bias model:

  • Makes strong assumptions
  • Learns too little
  • Misses important patterns
  • Produces systematic errors

Simple Definition

Bias = Error due to overly simple assumptions

High Bias Model Visualization

Characteristics of High Bias

PropertyDescription
Model complexityVery low
Learning abilityWeak
Training accuracyPoor
Testing accuracyPoor
ProblemUnderfitting

What is Variance?

Variance describes how much a model's predictions can change when the training data changes. High variance often means the model is too sensitive to the particular examples it saw.

A high-variance model:

  • May learn noise
  • May fit noise or unimportant details
  • Changes drastically with small dataset changes
  • Performs poorly on unseen data

Simple Definition

Variance = Error due to excessive sensitivity

High Variance Visualization

Characteristics of High Variance

PropertyDescription
Model complexityVery high
MemorizationHigh
Training accuracyExtremely high
Testing accuracyPoor
ProblemOverfitting

What is the Bias-Variance Tradeoff?

The Bias-Variance Tradeoff describes how changing model flexibility can change two kinds of error. Very simple models can miss the real pattern, while very flexible models can become too sensitive to the particular training sample.

Increasing Model Complexity

  • Reduces bias
  • Increases variance

Reducing Model Complexity

  • Increases bias
  • Reduces variance

The practical goal is to choose a model that performs well on unseen data — not simply the model with the lowest training error.

Bias-Variance Curve

In this teaching illustration, the best region is where the total expected error is lowest.

Key Observation

As model complexity increases: Bias decreases and Variance increases. Optimal performance occurs in the middle.


Mathematical Understanding

For squared-error regression, the expected prediction error is commonly explained using this decomposition:

Expected Squared Error ≈ Bias² + Variance + Irreducible Noise

This is a useful way to understand the tradeoff. It is not a universal formula for every possible loss function or machine-learning problem.

Formula Explanation

1. Bias²

Error caused by oversimplification.

2. Variance

Error caused by sensitivity to training data.

3. Irreducible Error

Random noise that cannot be removed.

Worked Numerical Example

Suppose a simple squared-error decomposition gives:

Bias²4Systematic error from the model's simplifying assumptions
Variance3Sensitivity to changes in the training sample
Irreducible noise2Random variation the model cannot fully remove

Step 1 — Write the three parts

Error ≈ 4 + 3 + 2

We substitute the given Bias², Variance and noise values.

Step 2 — Add Bias² and Variance

4 + 3 = 7

These are the two parts we try to balance when choosing model complexity.

Step 3 — Add irreducible noise

7 + 2 = 9

So the expected squared error in this simplified example is about 9.


Real-World Example — House Price Prediction

Suppose we want to predict house prices.

High Bias Model

Uses only:

  • House Size

Ignores:

  • Location
  • Bedrooms
  • Age
  • Amenities

Prediction quality becomes poor.

High Variance Model

Uses:

  • House Size
  • Wall Color
  • Owner Name
  • Door Shape
  • Plant Count

Model learns noise and irrelevant patterns.

Balanced Model

Uses:

  • House Size
  • Location
  • Bedrooms
  • Bathrooms

This creates good generalization.


Bias and Variance in Different Algorithms

The table below shows common tendencies, not permanent labels. Bias and variance depend on model settings, data size, regularization, feature quality, and the problem itself.

AlgorithmBiasVariance
Linear RegressionCan be higher if the true pattern is strongly non-linearOften relatively low
Polynomial Regression (High Degree)LowHigh
Decision TreesOften lower when trees are deepCan be high for deep, unpruned trees
Random ForestDepends on tree settingsUsually lower than a single deep tree
Neural NetworksCan fit very complex patternsCan overfit without enough data or regularization
Ridge RegressionSlightly HigherLower

Understanding Underfitting

Underfitting occurs when a model is not flexible enough, not trained enough, or does not have enough useful information to capture the important pattern.

  • Fails to learn patterns
  • High training error
  • High testing error

Causes and Solutions for Underfitting

Causes

  • Very simple model: Cannot capture patterns
  • Too few features: Missing information
  • Excessive regularization: Over-constrained learning
  • Insufficient training: Weak learning

Solutions

  • Increase model complexity
  • Add features
  • Reduce regularization
  • Train longer if optimization has not yet converged

Understanding Overfitting

Overfitting occurs when a model fits the training data so closely that some of what it learns does not generalize well to new data.

  • Excellent training accuracy
  • Poor testing accuracy
  • May fit noise or accidental details
  • Weak generalization

Causes and Solutions for Overfitting

Causes

  • Too many features: Excess complexity
  • Very powerful model: Learns noise
  • Small dataset: Insufficient examples
  • Weak regularization: No complexity control

Solutions

  • Use regularization
  • Remove unhelpful features when appropriate
  • Use more representative training data when available
  • Use cross-validation
  • Simplify the model

How Can You Recognize High Bias or High Variance?

A practical first check is to compare performance on the training set with performance on validation data.

Training ErrorValidation ErrorWhat It May Suggest
HighHighPossible underfitting / high bias
LowMuch higherPossible overfitting / high variance
LowLow and close to training errorBetter sign of generalization

Important:

These are clues, not automatic diagnoses. Always consider the metric, dataset size, noise, class balance, and whether the validation data truly represents the problem.


Cross-Validation & Deep Learning

Cross-validation helps estimate how a model may perform on unseen data and compare model or hyperparameter choices more reliably. Comparing training performance with validation performance can also provide clues about underfitting or overfitting.

Cross-Validation Workflow

Dataset
↓
Split into folds
↓
Train multiple times
↓
Average performance
↓
Estimate generalization

Deep neural networks are highly flexible models. They can achieve very low training error, but they can still overfit when the dataset, regularization, or training setup is not appropriate.

  • Dropout: Reduce variance
  • Early stopping: Prevent overfitting
  • Batch normalization: Stabilize training
  • Data augmentation: Improve generalization

Python Example

Underfitting vs Overfitting using Scikit-Learn.

import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression

X = np.array([1,2,3,4,5,6]).reshape(-1,1)
Y = np.array([1,4,9,16,25,36])

# Step 3 - Low Degree Polynomial -> Underfitting
poly1 = PolynomialFeatures(degree=1)

# Step 4 - Medium Degree Polynomial -> Balanced fitting
poly2 = PolynomialFeatures(degree=2)

# Step 5 - A very high degree can overfit a small dataset
poly10 = PolynomialFeatures(degree=10)

Common Questions About Bias and Variance

Is high bias the same as underfitting?

They are closely related, but not identical definitions. High bias often leads to underfitting because the model cannot capture enough of the true pattern.

Is high variance the same as overfitting?

High variance is commonly associated with overfitting: the model changes too much with the training sample and may perform much worse on new data.

Does a more complex model always have lower bias and higher variance?

It is a useful general tendency, not a guaranteed rule. Regularization, data size, model architecture, and training procedure can change the behavior.

Final Summary

The Bias-Variance Tradeoff helps explain why both overly simple and overly flexible models can perform poorly on unseen data. High bias is commonly associated with underfitting, while high variance is commonly associated with overfitting.

In practice, we compare training and validation performance, use cross-validation where appropriate, and tune model complexity or regularization to find a model that generalizes well.

Most Important Insight to Remember:

"Very low training error is not enough. A useful model must also perform well on representative data it did not train on."

Apply this concept in a real hands-on project

You have studied the idea. Now use it in working Python code, see the calculation and output, and explain what changed. Each project includes step-by-step instructions, full source and tests.

Practice challenge: predict an outcome first, run the code, and explain the difference.

Track Your Progress0% curriculum done

Finished "Bias-Variance Tradeoff"?

Mark this lesson as completed to update your progress bar and track your milestones across the full curriculum.

Overall Progress0 / 167 lessons

Was this tutorial helpful?

Your feedback helps us continuously refine and improve our open-access tutorials.

Summary / Key Takeaways

  • High bias underfits because the model is too restricted.
  • High variance follows training-specific noise and becomes unstable.
  • Training and validation curves help distinguish the two problems.
  • Greater flexibility often reduces bias while increasing variance risk.
  • Regularization, data, ensembling, and simplification change the trade-off.
  • Choose complexity from held-out performance, not training error.

Knowledge Check

Progress: 0/4

Test your active recall. Choose one answer for each question, then check it to reveal the step-by-step reasoning.

Question 1 of 4
A decision tree achieves 99.8% training accuracy and 61% test accuracy. What is the specific problem and what are two concrete fixes?
Question 2 of 4
Training accuracy is 64% and validation accuracy is 62% on a 10-class classification problem. Both have been stable for many epochs. What is the diagnosis?
Question 3 of 4
You have high variance. Which intervention is most likely to help: collecting more training data or reducing regularisation?
Question 4 of 4
What does 'irreducible error' mean in the bias-variance decomposition, and what can you do about it?

Knowledge Check Review & Explanations

Review the questions, verified correct answers, and conceptual explanations for this lesson.

1A decision tree achieves 99.8% training accuracy and 61% test accuracy. What is the specific problem and what are two concrete fixes?▼

Correct Answer: High variance (overfitting) — fix by limiting tree depth with max_depth and requiring a minimum number of samples per leaf with min_samples_leaf

The 38-point training-test gap is classic overfitting. An unconstrained decision tree memorises training examples. max_depth limits how deep the tree can grow; min_samples_leaf prevents the model from fitting individual examples.

2Training accuracy is 64% and validation accuracy is 62% on a 10-class classification problem. Both have been stable for many epochs. What is the diagnosis?▼

Correct Answer: High bias — the model is underfitting. Both train and validation are poor, meaning the model lacks the capacity to learn the patterns in this problem

When training and validation accuracy are both poor AND similar (small gap between them), the model is underfitting. There is no evidence of overfitting (which would show a large gap). Fix: increase model complexity, add features, reduce regularisation, or train longer.

3You have high variance. Which intervention is most likely to help: collecting more training data or reducing regularisation?▼

Correct Answer: Collecting more training data — more examples make it harder for the model to memorise quirks, forcing it to learn general patterns. Reducing regularisation would increase variance, making the problem worse

High variance means the model is overfitting — too sensitive to the specific training examples. More data dilutes the influence of individual noisy examples. Reducing regularisation loosens the constraints that prevent overfitting, which would worsen variance.

4What does 'irreducible error' mean in the bias-variance decomposition, and what can you do about it?▼

Correct Answer: Error inherent in the data itself — measurement noise, missing causal variables, genuine randomness. No model, no matter how complex, can eliminate it. You can minimise bias + variance but irreducible error is a floor

If you could perfectly predict whether someone will default on a loan, there would still be some people who genuinely could go either way depending on unforeseen life events. That inherent unpredictability is irreducible error.

Keep moving through the path

Continue Learning

Free Download: ML Interview Cheatsheet

100 essential Machine Learning interview questions and answers covering foundations, algorithms, evaluation, deep learning, Python, system design and interview strategy. Enter your email to download it instantly.

Optional Learning Resources

These resources may complement the lesson. They are optional and are not required to use ML Academy.

As an Amazon Associate I earn from qualifying purchases. Other links are identified separately when they are not affiliate links.

Next