Machine Learning

Bias-Variance Decomposition

Bias-variance decomposition separates generalization error into target mismatch, training-set instability, and irreducible noise.

status: publishedimportance: criticaldifficulty 3/5math: undergraduateread: 19mlive demo

Concept Structure

Bias-Variance Decomposition

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
0next concepts
1related links

Learning map

Bias-Variance Decomposition
BeforeLinear Regression & Least SquaresNow4/4 sections readyTryManipulate one control and predict the visible change.NextClassification Metrics, Thresholds, and Calibration

Object flow

4/4 sections readyAsk about thisResearch room
ConceptBias-Variance DecompositionMachine Learning
2 sources attachedLocal snapshot ready
concept:machine-learning/bias-variance-decomposition

Conceptual Bridge

What should feel connected as you move through this page.

Carry inLinear Regression & Least Squares

Bring the mental model from Linear Regression & Least Squares; this page will reuse it instead of restarting from zero.

Work hereBias-Variance Decomposition

Bias-variance decomposition separates generalization error into target mismatch, training-set instability, and irreducible noise.

Carry outClassification Metrics, Thresholds, and Calibration

The next edge should feel earned: use the demo prediction here before following Classification Metrics, Thresholds, and Calibration.

Test the linkManipulate one control and predict the visible change.Then continue to Classification Metrics, Thresholds, and Calibration
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

You are here because "overfitting" is too vague by itself. A model can fail because it is systematically wrong, because it changes too much when the training data changes, or because the target is noisy even in the best possible world.

Before this, know least-squares regression. By the end, you should be able to name the randomness source in the decomposition, predict when a model is bias-dominated or variance-dominated, and run a small resampling witness.

Bias-variance is about imagined repeats of the training process. Hold one test input x0x_0 fixed. Now imagine drawing many different training sets from the same data-generating process, fitting a model on each one, and asking how the predictions at x0x_0 vary.

Three things can hurt expected squared error:

Bias is systematic miss. If the average fitted model is far from the true function, the model class is not flexible enough or the features are wrong.

Variance is training-set sensitivity. If different training sets produce very different predictions at the same x0x_0, the model is flexible enough to chase sample noise.

Noise is irreducible target randomness. If the observed label is f(x0)+ϵf^\star(x_0)+\epsilon, no model can predict the fresh ϵ\epsilon before it happens.

The common trap is to treat bias and variance as properties of one fitted curve. They are properties of the learning procedure under repeated samples.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Fix an input x0x_0. Suppose the data-generating process is

Y=f(x0)+ϵ,Y=f^\star(x_0)+\epsilon,

where f(x0)f^\star(x_0) is the true conditional mean and ϵ\epsilon has mean 00 and variance σ2\sigma^2. Let f^D(x0)\hat f_D(x_0) be the prediction made by a model trained on dataset DD. The randomness in f^D\hat f_D comes from the draw of DD.

The expected squared prediction error at x0x_0 is

ED,ϵ[(Yf^D(x0))2].\mathbb E_{D,\epsilon}\left[(Y-\hat f_D(x_0))^2\right].

Add and subtract the average fitted prediction fˉ(x0)=ED[f^D(x0)]\bar f(x_0)=\mathbb E_D[\hat f_D(x_0)]:

Yf^D(x0)=ϵ+(f(x0)fˉ(x0))+(fˉ(x0)f^D(x0)).Y-\hat f_D(x_0) = \epsilon + \left(f^\star(x_0)-\bar f(x_0)\right) + \left(\bar f(x_0)-\hat f_D(x_0)\right).

When ϵ\epsilon has mean 00 and is independent of the training-set draw, the cross terms vanish after expectation. The decomposition becomes

ED,ϵ[(Yf^D(x0))2]=σ2+(f(x0)fˉ(x0))2+ED[(f^D(x0)fˉ(x0))2].\mathbb E_{D,\epsilon}\left[(Y-\hat f_D(x_0))^2\right] = \sigma^2 + \left(f^\star(x_0)-\bar f(x_0)\right)^2 + \mathbb E_D\left[\left(\hat f_D(x_0)-\bar f(x_0)\right)^2\right].

These are:

noise+bias2+variance.\text{noise}+\text{bias}^2+\text{variance}.

The decomposition is local to an input x0x_0. A model can be low-bias in one region and high-bias elsewhere. Whole-dataset generalization error averages this picture over the input distribution.

The formula also assumes the fresh test noise has mean 00, has variance σ2\sigma^2, and is independent of the training-set draw. If those assumptions change, the clean three-term story can pick up extra terms.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

rng = np.random.default_rng(7)
probe = 1.4
noise_sd = 0.25

def f_star(x):
    return np.sin(1.4 * x)

def one_fit(degree, n=18):
    x = rng.uniform(-3, 3, size=n)
    y = f_star(x) + rng.normal(0, noise_sd, size=n)
    coeff = np.polyfit(x, y, deg=degree)
    return np.polyval(coeff, probe)

for degree in [1, 3, 9]:
    preds = np.array([one_fit(degree) for _ in range(300)])
    mean_pred = preds.mean()
    bias2 = (mean_pred - f_star(probe)) ** 2
    variance = preds.var()
    expected_error = noise_sd ** 2 + bias2 + variance
    print("degree", degree)
    print("  bias^2:", round(bias2, 4))
    print("  variance:", round(variance, 4))
    print("  noise:", round(noise_sd ** 2, 4))
    print("  total:", round(expected_error, 4))

The code mirrors the math: each call to one_fit draws a new training set DD, preds estimates the distribution of f^D(x0)\hat f_D(x_0), and the mean of those predictions estimates $\bar f(x_0)`. These are Monte Carlo estimates, not exact values. High-degree raw polynomial fits can also add numerical conditioning artifacts; that is a separate problem from statistical variance.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Choose model flexibility, training-set size, noise, and a probe point. Before revealing the resampled fits, predict which term dominates the local error at the probe: bias, variance, noise, or a rough balance.

The reveal overlays many fitted curves from different training sets. If the average curve misses the true function at the probe, bias dominates. If the curves disagree with each other at the probe, variance dominates. If both are small relative to the noise slider, the remaining error is irreducible noise. The answer is local to the probe point and estimated from a finite set of resamples.

The noise readout is the variance σ2\sigma^2, not the noise standard deviation. The fitted curves are a finite Monte Carlo witness, and the polynomial solver uses a tiny stabilizer so numerical blow-ups do not masquerade as statistical variance.

Live Concept Demo

Explore Bias-Variance Decomposition

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Bias-Variance Decomposition should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Bias-variance decomposition separates generalization error into target mismatch, training-set instability, and irreducible noise.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Bias-Variance Decomposition should make visible.

Visual Inquiry

Make the image answer a mathematical question

Bias-variance decomposition separates generalization error into target mismatch, training-set instability, and irreducible noise.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Bias-Variance Decomposition easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

book · 2023An Introduction to Statistical LearningJames, Witten, Hastie, Tibshirani, and Taylor

Claim source for expected test MSE at a fixed x0 and repeated-training-set bias-variance decomposition.

Open source
bookThe Elements of Statistical LearningHastie, Tibshirani, and Friedman

Curriculum source for statistical-learning decomposition and resampling intuition.

Open source

Claim Review

Bias-variance decomposition separates generalization error into target mismatch, training-set instability, and irreducible noise.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources2 references

isl-bias-variance, esl-bias-variance

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedAt a fixed input under squared error, expected prediction error decomposes into irreducible noise, squared bias, and variance over training-set draws.Claim metadata: source checked

ISLR directly supports the page's local fixed-x0 decomposition, repeated-training-set expectation, variance/bias terminology, irreducible-error term, and model-flexibility tradeoff framing.

Sources: An Introduction to Statistical LearningThis source check covers squared-error regression at a fixed input under the stated noise/training-draw assumptions; finite-resample demos are Monte Carlo estimates and raw high-degree polynomial fits can add numerical artifacts.A bounded review summary is present; still check caveats and exact source scope.

Checked ISLR section 2.2.2: it states expected test MSE for a given x0 decomposes into variance of fhat(x0), squared bias, and Var(epsilon), and defines the expectation by repeatedly estimating f on many training sets and testing at x0. The page preserves fixed-input locality, training-set randomness, fresh-noise, Monte Carlo, and conditioning caveats.

Reviewer: codex+gpt-pro-prior; reviewed 2026-06-28

Practice Loop

Try the idea before it explains itself

Bias-variance decomposition separates generalization error into target mismatch, training-set instability, and irreducible noise.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Bias-Variance Decomposition.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptBias-Variance DecompositionMachine Learning

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptMachine Learning

Bias-Variance Decomposition

Anchored question

What is the smallest example that makes Bias-Variance Decomposition click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:machine-learning/bias-variance-decomposition.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: isl-bias-variance, esl-bias-variance
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Bias-Variance Decomposition Object key: concept:machine-learning/bias-variance-decomposition Context: Machine Learning Anchor id: concept/concept-notebook/machine-learning/bias-variance-decomposition Open question: What is the smallest example that makes Bias-Variance Decomposition click without losing the math? Evidence to inspect: - Source ids to inspect: isl-bias-variance, esl-bias-variance - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/machine-learning/bias-variance-decomposition concept:machine-learning/bias-variance-decomposition