Skip to content
AI360XpertBeta
Playgrounds

Foundations

Bias–variance trade-off

A more flexible curve can follow the signal better while becoming more sensitive to the particular training sample.

Data seed 20261010

Guided steps 1 / 5

Stage 1 of 5: Same signal

Samples and the true signal

Degree 1. 20 training and 20 held-out observations. Noise standard deviation 0.20.

Dotted reference: true signal. Change the sample size or noise, or draw new data.

  • Training sample
  • Held-out sample
Adjust parameters

Training points; the held-out sample has the same size.

Scatter around the true curve, in target units.

Sample size20Sample size: 20

What stays the same when the observations change?

Circles train the model; squares are held back for scoring. Both come from the dashed true curve plus independent noise. Change the noise or draw new data.

  1. sample
  2. fit
  3. prediction
  4. independent error
Noise

Random variation in an observation around the true function. Its standard deviation is the noise control.

Check this stage

Check your understanding

A curve can fit its training points closely and still miss fresh observations. Change its degree, then compare twenty independent fits to see systematic error and sample sensitivity separately.

Can a small training error fool you?

Start with Same signal. Circles are training observations; squares are an independent held-out sample. The dotted reference is the true signal, which stays fixed when you choose New data. Raising Noise standard deviation scatters observations further from that signal.

In A line misses, change Polynomial degree from 1 to 3. A line cannot follow the bend; a cubic can. Degree counts the highest power of the input, so degree 9 means ten fitted coefficients, including the intercept. It does not mean enough freedom to hit any number of noisy points.

Break the fit, then recover

Open Fit the noise and choose Degree 9 on eight points. Compare the training and held-out MSE, the average squared difference between predictions and observations. The drawing stops at the frame when predictions escape its range; the numeric errors use their full values.

Choose Back to working to restore the previous settings and seed. Or raise Sample size to 40 and compare the same degree again. More observations constrain the coefficients, although a single split cannot promise an improvement every time. The solver uses a small ridge penalty of 1e−9, including the intercept. With eight points and ten coefficients, that penalty selects a solution from an underdetermined problem; this is not unregularised exact interpolation.

In Choose a degree, place a guess before revealing the held-out curve. Drag the diamond, or use the degree slider, to select its lowest score. This uses validation data to choose a setting. Keep a separate test set if you want a final assessment that has not influenced the choice. Train/test splitting lets you inspect that distinction.

What changes across twenty training sets?

Open Twenty fits. Each faint dashed curve is fitted with the same degree, sample size and noise, but a different training draw. The heavy solid curve is their mean. The offset between that mean and truth estimates bias; the spread of individual predictions around the mean estimates variance. A single curve's mistake is not a measurement of bias.

Try degree 1, then degree 9. Choose Resample twenty to draw a fresh batch. Change the sample size and watch the whole family refit. Pin this fit keeps a separate comparison curve; it is not included as another member of the twenty-fit estimate. Drag the inspection diamond along the true curve, or use Inspect input x, and read the same values in Under the hood.

For squared error with independent, zero-mean target noise:

ED,Y[(f^D(x)−Y)2]=(ED[f^D(x)]−f(x))2+ED[(f^D(x)−ED[f^D(x)])2]+σ2.\mathbb{E}_{D,Y}[(\hat f_D(x)-Y)^2] = (\mathbb{E}_D[\hat f_D(x)]-f(x))^2 + \mathbb{E}_D[(\hat f_D(x)-\mathbb{E}_D[\hat f_D(x)])^2] + \sigma^2.

Here DD is a training set, f^D(x)\hat f_D(x) its fitted prediction, f(x)f(x) the true mean target, YY a fresh noisy observation and σ\sigma the noise standard deviation. The expectation averages over training sets and fresh targets at a fixed input. The lab then averages over a fixed grid of inputs from −1 to 1.

A small example makes the split checkable. Suppose truth is 2 and two fitted models predict 1 and 5. Their mean is 3, so squared bias is (3−2)2=1(3-2)^2=1. Variance is ((1−3)2+(5−3)2)/2=4((1-3)^2+(5-3)^2)/2=4. With noise standard deviation 0.5, the noise variance is 0.52=0.250.5^2=0.25. Expected squared error is 1+4+0.25=5.251+4+0.25=5.25. An oracle that always predicts truth can have zero bias and zero variance while target noise remains.

What this experiment cannot tell you

The decomposition is an estimate from twenty fits and 101 equally weighted inputs, not an exact population expectation. Rare extreme polynomial fits can dominate it. It describes a randomly drawn fitted model on fresh targets, not the error of the mean curve. The current held-out MSE uses a different, finite set of observations and need not equal the decomposition total.

A U-shaped validation curve is common in this example, but it is not a law for every seed or learning algorithm. More complex models can behave differently beyond the interpolation threshold. The squared-error identity still holds; it does not dictate how each term must move with complexity.

The repeated-fit view follows the distinction between average prediction and spread in scikit-learn's decomposition example. The expectation and independent-noise assumptions follow Cornell's derivation. Toronto's notes explain why the identity survives more complicated capacity/error relationships.

Stage recap

  1. Same signal

    Circles train the model; squares are held back for scoring. Both come from the dashed true curve plus independent noise. Change the noise or draw new data.

  2. A line misses

    Start at degree 1, then allow more bends. A single mismatch is not a measurement of bias; the final stage compares the average of repeated fits with truth.

  3. Fit the noise

    Push the degree up and reduce the sample size. The fitted curve can escape the visible range. The numeric errors stay unclamped, even when the drawing reaches the frame.

  4. Choose a degree

    Place your guess, then reveal the held-out curve. Drag the diamond to change the fitted degree. The lowest point selects a candidate for this sample, not a universal best degree.

  5. Twenty fits

    The faint dashed curves use twenty training draws at the same settings. Their heavy mean shows the average prediction. Its offset from truth is bias; spread about it is variance.

Reference

Squared bias
Squared distance between the mean prediction across training sets and the true function, averaged over inputs.
Variance
Mean squared spread of predictions about their mean. The twenty-fit empirical estimate uses divisor twenty.
Expected prediction MSE
Squared bias + variance + independent target-noise variance. Estimated here over twenty fits and a fixed input grid; distinct from current held-out MSE.
Numerical ridge
The polynomial solver adds 1e−9 to the normal-equation diagonal, including the intercept. This selects a stable solution when points are fewer than coefficients.

Break it on purpose

Set degree to 9, sample size to 8 and noise to 0.20. Compare training and held-out error, then draw new data. The small ridge penalty selects a fit from an underdetermined problem; low training error does not guarantee good predictions. Add data or lower the degree and compare again.