Designing a Sample-Wise Double Descent Experiment in Linear Regression
Machine LearningModel answerLast updated
Design and analyze a synthetic linear regression experiment that demonstrates how test error spikes near the interpolation threshold as sample size varies.
Background
Classical statistical learning theory predicts that test error should decrease monotonically as you collect more training data. Modern high-dimensional practice tells a different story: there is a critical sample size where test error spikes dramatically before dropping again as you add even more data. This non-monotone behavior — where the risk curve dips, rises sharply, then dips again — is called double descent, and it appears even in the simplest models.
Your task is to propose a rigorous, reproducible synthetic experiment that isolates and demonstrates sample-wise double descent in linear regression, and to explain the mathematical mechanisms behind it.
What to Design
You are fixing the feature dimension d and varying the number of training samples n. Describe each component of the experiment clearly:
1. Data Generating Process
Specify the distribution of input features, the ground-truth weight vector, and how targets are produced: y = xᵀw* + ε with additive Gaussian noise σ². Choose concrete values for all hyperparameters and justify them.
2. Estimator Identify the estimator to use in each regime:
- When
n > d(more samples than features): which standard estimator applies, and under what conditions is it defined? - When
n < d(fewer samples than features): the system is underdetermined; what criterion selects a unique solution, and what is the closed-form expression?
Describe a single unified implementation that handles both regimes automatically.
3. Evaluation Protocol
Explain how to measure test risk without relying on a held-out test set (hint: use the problem's structure). Specify the sweep range for n, the sampling density around the critical region n ≈ d, the number of independent trials per n, and why the mean may be misleading near n = d.
Analysis Questions
Address each of the following in your answer:
A. Why does the error peak at n ≈ d?
Use the singular value decomposition of the design matrix X to explain what happens to the smallest singular values as n approaches d. Connect this to how noise enters the estimator.
B. Bias and variance across the threshold
Provide the exact expressions for bias and variance in both the underparameterized (n > d) and overparameterized (n < d) regimes. Which term drives the peak — bias, variance, or both? What happens to each as n crosses d?
C. What if label noise is zero?
Set σ² = 0 and describe the resulting risk curve. Does the peak survive? Give a precise explanation, and describe a realistic scenario where a peak can re-emerge even without additive noise.
What a Strong Answer Looks Like
A strong answer provides: concrete parameter choices with justification, a unified Python implementation, closed-form theoretical risk curves that the simulation can be checked against, precise mathematical statements about singular value behavior, a clean separation of bias and variance, and correct handling of the degenerate points n ∈ {d−1, d, d+1}. Discuss at least one follow-up extension (e.g., effect of ridge regularization or anisotropic features).
Hints
Hint 1
The peak's height is controlled by the smallest nonzero singular value of X. Random matrix theory tells you exactly how that value behaves as n approaches d — write it down explicitly before trying to explain the risk formula.
Hint 2
For isotropic Gaussian features, test risk has a closed form: E[(xᵀŵ − y)²] = ||ŵ − w*||² + σ². You do not need a test set at all. This also means you can overlay a theoretical curve on your simulation as a sanity check.
Hint 3
Bias and variance behave very differently near the threshold: one is smooth and linear in n, the other diverges. Figuring out which is which will tell you exactly why σ² = 0 eliminates the peak — and what has to be true about a noise-free problem for the peak to return.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
What This Question Is Really Assessing
The interviewer wants to see three things together: the ability to construct a controlled experiment where outcomes can be predicted analytically, a working understanding of how matrix conditioning connects to generalization error, and a clean decomposition of bias versus variance across the interpolation threshold. The strongest answers derive closed-form risk curves so the simulation serves as a verification rather than a discovery.
1. Experimental Setup
Data generating process
Fix d = 100. Draw features x ~ N(0, I_d) — isotropic Gaussian, so there is no preferred direction and the math stays clean. Sample the ground-truth weight vector uniformly on the unit sphere: ||w*||² = 1, redrawn each trial. Generate labels as y = xᵀw* + ε with ε ~ N(0, σ²) and σ² = 0.25. Also run σ² = 0 to answer the noise question.
Estimator
Use ŵ = pinv(X) @ y throughout. When n > d and X has full column rank, this equals the OLS solution (XᵀX)⁻¹Xᵀy. When n < d, it produces the minimum-L2-norm interpolator Xᵀ(XXᵀ)⁻¹y — the point in the solution manifold closest to the origin. A single call to np.linalg.pinv handles both regimes automatically, with one important caveat: do not apply an rcond cutoff or add any implicit regularization, as this will truncate small singular values and hide the peak.
Evaluation protocol
Because features are isotropic Gaussian, the test risk reduces to:
R(ŵ) = ||ŵ − w*||² + σ²
This eliminates test-set sampling noise entirely. Sweep n from 10 to 300 in steps of 10, and use a step of 1 for n ∈ [80, 120] to resolve the peak. Run 200 independent trials per n, each with fresh X, w*, and ε. Report both the mean and the median. Near n = d the risk distribution is heavy-tailed and the population mean is literally infinite at n ∈ {d−1, d, d+1} (see Section 2); empirical means there will be unstable. The median is a more informative summary in that region.
import numpy as np
def risk_curve(d=100, ns=None, sigma=0.5, trials=200, seed=0):
if ns is None:
ns = list(range(10, 80)) + list(range(80, 121)) + list(range(130, 301, 10))
rng = np.random.default_rng(seed)
results = {}
for n in ns:
risks = []
for _ in range(trials):
w = rng.standard_normal(d)
w /= np.linalg.norm(w) # unit sphere
X = rng.standard_normal((n, d))
y = X @ w + sigma * rng.standard_normal(n)
w_hat = np.linalg.pinv(X) @ y # no rcond cutoff
risks.append(np.sum((w_hat - w) ** 2) + sigma ** 2)
results[n] = {"mean": np.mean(risks), "median": np.median(risks)}
return results
2. Why the Peak Sits at n ≈ d
Write the SVD of the design matrix as X = USVᵀ, with nonzero singular values s₁ ≥ … ≥ sₖ where k = min(n, d).
Noise enters the estimate through pinv(X) ε = VS⁻¹Uᵀε. Its expected squared norm is:
σ² · Σᵢ 1/sᵢ² = σ² · tr((XᵀX)⁺)
The error is therefore dominated by the smallest nonzero singular value. Random matrix theory (the Bai–Yin law) gives:
s_min(X) ≈ √n − √d → 0 as n → d
As n → d from either side, this edge collapses toward zero. A tiny s_min means there is a direction the data barely measures. Fitting the labels along that direction forces the estimator to use a coefficient of order 1/s_min, which amplifies noise by 1/s_min². When n is well above or well below d, the spectrum separates from zero and amplification stays bounded. The divergence is two-sided and symmetric, which is why the peak is centered at n = d.
3. Bias-Variance Decomposition
Underparameterized regime, n > d + 1
OLS is unbiased, so bias = 0. The variance term has an exact closed form via inverse-Wishart moments:
Variance = σ² · E[tr((XᵀX)⁻¹)] = σ²d / (n − d − 1)
This is finite only for n > d + 1, decreases as n grows, and diverges as n ↓ d + 1.
Overparameterized regime, n < d − 1
The minimum-norm estimator projects w* onto the row space of X. The part of the signal lying in the null space is unrecoverable:
Bias = ||(I − Pₓ)w*||² = 1 − n/d
This is linear in n, smooth, and entirely well-behaved. The variance term is:
Variance = σ² · E[tr((XXᵀ)⁻¹)] = σ²n / (d − n − 1)
This diverges as n ↑ d − 1.
The key insight
Bias is smooth and monotonically decreasing — it never spikes. Variance diverges on both sides of n = d. The peak is a variance phenomenon, not a bias phenomenon. A common mistake is attributing the bump to bias, which has no discontinuity there.
4. The Noise-Free Case, σ² = 0
With no additive noise, the variance term vanishes identically. The risk becomes:
R = 1 − n/d for n < d, 0 for n ≥ d
This is strictly decreasing. There is no peak.
Ill-conditioning by itself is not harmful when labels are exactly consistent with w*. The small singular values only cause damage when they multiply something that is not signal — namely, the noise vector ε.
When the peak reappears despite σ² = 0
Suppose the true model has D > d features but the estimator only sees d of them. The omitted signal x_hiddenᵀw_hidden acts as effective noise with variance ||w_hidden||². The interpolation peak re-emerges even though ε = 0. This is model misspecification masquerading as noise — an important point for practitioners who believe clean labels protect them from double descent.
Common Mistakes
- Averaging at exactly n = d. The expected risk is infinite there. A few large outliers produce spurious smooth humps or huge variance. Skip
n ∈ {d−1, d, d+1}or report medians. - Using lstsq with an rcond threshold. This truncates small singular values and smooths away the peak — the simulation appears to contradict theory.
- Claiming bias causes the spike. Bias has no singularity at
n = d. Variance does. - Fixing w* across trials without stating it. This is fine for isotropic features, but the bias formula
1 − n/dassumes either a random direction or careful averaging over orientations.
Follow-Up: Ridge Regularization
Adding λ > 0 gives the estimator (XᵀX + λI)⁻¹Xᵀy. Each singular direction is now scaled by sᵢ/(sᵢ² + λ), bounded above by 1/(2√λ) regardless of how small sᵢ gets. The peak is capped and smoothed. With the optimally tuned penalty λ* = dσ²/r², the test risk curve becomes monotone in n and double descent disappears entirely. A too-small λ leaves a damped bump; a too-large λ raises bias uniformly. This is a direct argument for why even weak regularization matters near the interpolation threshold.