Simple Algorithm
Machine Learning · Convergence · 26 min

Learning Curves & Sample Size

How error falls with more data, and the shapes curves really take.

How much will the next ten thousand labeled examples buy you? The answer is the learning curve: expected error as a function of sample size. Theory pins down its shape in clean cases, 1/n1/n for regular parametric models and n−2s/(2s+d)n^{-2s/(2s+d)} for smooth nonparametric ones. Practice finds power laws with stubbornly small exponents. And both find curves that go up when more data arrive.

What you’ll learn

  • Define expected learning curves, and prove that the expected training error of empirical risk minimization never decreases with nn, while its test error need not be monotone.
  • Derive the parametric rates pσ2/(n−p−1)p\sigma^2/(n-p-1) and d/(2n)d/(2n), and the nonparametric rate n−2s/(2s+d)n^{-2s/(2s+d)} from a bias–variance balance.
  • Explain sample-wise double descent and what is known about monotone learners.
  • Fit and extrapolate power-law learning curves to decide whether to collect more data, and recognize when extrapolation fails.

Learning curves, precisely

Fix a distribution PP and a learning algorithm AA. The expected learning curve is Rˉ(n)=ED∼Pn[R(A(D))]\bar R(n)=\E_{\data\sim P^n}\big[R(A(\data))\big], and the training curve is Tˉ(n)=ED∼Pn[R^n(A(D))]\bar T(n)=\E_{\data\sim P^n}\big[\hat R_n(A(\data))\big]. In practice you estimate Rˉ\bar R by training on random subsets of several sizes, repeating each size a few times, and averaging validation errors. (The loss-versus-iterations plot of a single training run is a different object, sometimes also called a learning curve; this lesson is about sample size.)

For empirical risk minimization over a class H\mathcal H with best-in-class predictor h∘h^\circ, training error is optimistic, Tˉ(n)≤R(h∘)≤Rˉ(n)\bar T(n)\le R(h^\circ)\le\bar R(n), and one half of the picture is always well behaved:

DerivationProof
  1. R^n+1(h)=1n+1∑j=1n+1R^(−j)(h),R^(−j)(h)=1n∑i≠jℓ(h(xi),yi)\hat R_{n+1}(h)=\frac1{n+1}\sum_{j=1}^{n+1}\hat R^{(-j)}(h),\qquad \hat R^{(-j)}(h)=\frac1n\sum_{i\ne j}\ell\big(h(\mathbf x_i),y_i\big)

    Write the empirical risk on n+1n+1 points as the average of the n+1n+1 empirical risks that leave one point out, since each point appears in exactly nn of the n+1n+1 subsets:

  2. min⁡h∈HR^n+1(h) ≥ 1n+1∑j=1n+1min⁡h∈HR^(−j)(h)\min_{h\in\mathcal H}\hat R_{n+1}(h)\ \ge\ \frac1{n+1}\sum_{j=1}^{n+1}\min_{h\in\mathcal H}\hat R^{(-j)}(h)

    The minimum of an average is at least the average of the minima:

  3. Tˉ(n+1)=Emin⁡hR^n+1(h) ≥ Tˉ(n)\bar T(n+1)=\E\min_h\hat R_{n+1}(h)\ \ge\ \bar T(n)

    Each min⁡hR^(−j)(h)\min_h\hat R^{(-j)}(h) is the minimal empirical risk on an i.i.d. sample of size nn, so it has expectation Tˉ(n)\bar T(n). Taking expectations proves the claim.

No such argument exists for the test curve Rˉ(n)\bar R(n), and the last two steps of this lesson show it can rise. Viering, Mey & Loog (2019) posed monotonicity as an open problem, with simple examples in which ERM's expected risk does and does not decrease with each added example.

Parametric rates: one over n

For correctly specified, regular parametric models the excess risk falls like (number of parameters)/nn:

  • Least squares with pp coefficients and Gaussian inputs: Rˉ(n)−σ2=σ2p/(n−p−1)\bar R(n)-\sigma^2=\sigma^2p/(n-p-1) for n≥p+2n\ge p+2, exactly (from the mean of an inverse Wishart matrix, derived in Overfitting & the Bias–Variance Trade-off).
  • Maximum likelihood with dd parameters under log loss: the expected excess risk is the KL divergence from the true distribution to the fitted one, approximately d/(2n)d/(2n).
DerivationThe d/(2n) rate for maximum likelihood (sketch)
  1. DKL(pθ⋆ ∥ pθ^)≈12 (θ^−θ⋆)⊤I(θ⋆) (θ^−θ⋆)\KL\big(p_{\boldsymbol\theta^\star}\,\|\,p_{\hat{\boldsymbol\theta}}\big)\approx\tfrac12\,(\hat{\boldsymbol\theta}-\boldsymbol\theta^\star)^\top I(\boldsymbol\theta^\star)\,(\hat{\boldsymbol\theta}-\boldsymbol\theta^\star)

    For a model pθp_{\boldsymbol\theta} containing the truth θ⋆\boldsymbol\theta^\star, expand the excess log loss to second order around θ⋆\boldsymbol\theta^\star. The first-order term vanishes at the true parameter, and the Hessian there is the Fisher information I(θ⋆)I(\boldsymbol\theta^\star):

  2. E DKL(pθ⋆ ∥ pθ^)≈d2n\E\,\KL\big(p_{\boldsymbol\theta^\star}\,\|\,p_{\hat{\boldsymbol\theta}}\big)\approx\frac{d}{2n}

    The MLE is asymptotically normal, n(θ^−θ⋆)→N(0,I(θ⋆)−1)\sqrt n(\hat{\boldsymbol\theta}-\boldsymbol\theta^\star)\to\mathcal N\big(\mathbf 0,I(\boldsymbol\theta^\star)^{-1}\big), so n (θ^−θ⋆)⊤I (θ^−θ⋆)n\,(\hat{\boldsymbol\theta}-\boldsymbol\theta^\star)^\top I\,(\hat{\boldsymbol\theta}-\boldsymbol\theta^\star) is asymptotically χd2\chi^2_d, with mean dd:

Predict before you look

A correctly specified logistic regression with d=20d=20 parameters is fit to n=2,000n=2{,}000 examples. Approximately what expected excess log loss (in nats per example) does the d/(2n)d/(2n) rule predict?

Show the answer

0.005

d/(2n)=20/4000=0.005d/(2n)=20/4000=0.005 nats. Doubling the data halves it: the parametric learning curve is a power law with exponent −1-1. The approximation is asymptotic; with few examples per parameter, or with separable data where the MLE does not exist, it fails.

Classification theory gives the same flavor with combinatorial complexity in place of parameter counts: for a class of VC dimension dd, sample complexity scales like d/εd/\varepsilon in the realizable case and like d/ε2d/\varepsilon^2 in the agnostic case (Learning Theory: How Many Examples Are Enough?). These bounds hold uniformly over distributions. If the constants may depend on the (fixed) distribution, Bousquet, Hanneke, Moran, van Handel & Yehudayoff (2021) proved a trichotomy in the realizable case: the best achievable learning curves of any class decay either exponentially, linearly, or arbitrarily slowly, and which case holds is characterized by combinatorial parameters of the class. Uniform PAC bounds describe only the upper envelope of these curves.

Nonparametric rates and dimension

Without a parametric model, rates depend on smoothness and dimension. For regression functions on [0,1]d[0,1]^d with ss bounded derivatives, Stone (1982) proved that the optimal (minimax) rate for the squared L2L^2 error is n−2s/(2s+d)n^{-2s/(2s+d)}. The exponent comes from balancing bias against variance.

DerivationWhere n^{−2s/(2s+d)} comes from
  1. bias2≈C1h2s,variance≈C2 σ2n hd\text{bias}^2\approx C_1h^{2s},\qquad \text{variance}\approx\frac{C_2\,\sigma^2}{n\,h^d}

    A local averaging estimator (kernel smoothing, or local polynomials for s>2s>2) with bandwidth hh averages the labels in a window of volume ∝hd\propto h^d, which holds about nhdnh^d points. Smoothness bounds the bias by O(hs)\order{h^s}; averaging nhdnh^d independent noises gives the variance:

  2. h⋆∝n−1/(2s+d)⟹MSE(h⋆)∝n−2s/(2s+d)h^\star\propto n^{-1/(2s+d)}\quad\Longrightarrow\quad \text{MSE}(h^\star)\propto n^{-2s/(2s+d)}

    Minimize the sum over hh: the derivative vanishes when h2s+d∝1/nh^{2s+d}\propto1/n. Plug the optimal bandwidth back in:

Smoothness ssDimension ddExponent 2s/(2s+d)2s/(2s+d)Data needed to halve the error
210.8021/0.8≈2.4×2^{1/0.8}\approx2.4\times
220.67≈2.8×\approx2.8\times
2100.29≈11×\approx11\times
parametricany12×2\times
The curse of dimensionality in one column. Rates improve only if the problem has extra structure: more smoothness, a low intrinsic dimension, or a sparse or additive form.

Curves that go up

Take minimum-norm least squares (the interpolating solution X+yX^+\mathbf y when n<pn<p) with p=100p=100 isotropic Gaussian features, ∥β∥2=1\norm{\boldsymbol\beta}^2=1 and noise variance σ2=0.25\sigma^2=0.25. The exact expected excess risk is ∥β∥2(1−n/p)+σ2n/(p−n−1)\norm{\boldsymbol\beta}^2(1-n/p)+\sigma^2n/(p-n-1) for n≤p−2n\le p-2 and σ2p/(n−p−1)\sigma^2p/(n-p-1) for n≥p+2n\ge p+2: the bias is the part of β\boldsymbol\beta outside the nn-dimensional row space of XX, and the variance comes from the inverse-Wishart mean, as in the parent lesson. (Hastie, Montanari, Rosset & Tibshirani, 2022, analyze the limit p/n→γp/n\to\gamma of this and much more general models.) Read it as a learning curve:

nn10509095105110150300
excess risk0.930.762.66.06.32.80.510.13
Computed from the formulas above (a simulation with 2,000 repetitions agrees within 0.01 at n=50n=50 and n=150n=150). The risk is infinite for n=p−1n=p-1, pp and p+1p+1. Between n=50n=50 and n=100n=100, more data makes the predictor worse.

This is sample-wise double descent (Nakkiran, 2019: "more data can hurt"). Near n=pn=p the smallest singular value of XX approaches zero and the pseudo-inverse amplifies the noise; the peak is variance. Optimally tuned ridge removes it in this model, which is why the effect is rarely seen in carefully regularized practice; Double Descent in the modern-generalization lessons covers the model-wise version.

Can a learner always be made monotone? Bousquet, Daniely, Kaplan, Mansour, Moran & Stemmer (2022) showed that for multiclass classification every learning algorithm can be transformed, with black-box access, into a monotone one with similar performance, and that every PAC-learnable class has a monotone PAC learner, resolving the question for that setting.

Check your understanding

In the model above (p=100p=100, minimum-norm least squares), you grow the training set from n=50n=50 to n=90n=90. What happens to the expected excess risk?

  1. It falls from about 0.76 to about 0.42, as more data always helps
  2. It rises from about 0.76 to about 2.6, because the variance term σ2n/(p−n−1)\sigma^2n/(p-n-1) explodes as nn approaches pp
  3. It is unchanged, because pp is fixed
  4. It falls to zero, because the model still interpolates
Show the answer

B. It rises from about 0.76 to about 2.6, because the variance term σ2n/(p−n−1)\sigma^2n/(p-n-1) explodes as nn approaches pp

The bias term falls from 0.50.5 to 0.10.1, but the variance term rises from 0.25⋅50/49≈0.260.25\cdot50/49\approx0.26 to 0.25⋅90/9=2.50.25\cdot90/9=2.5. Interpolating noise with a nearly singular design is what hurts; past n≈pn\approx p the curve descends again.

Power laws at scale, and when to collect more data

Hestness et al. (2017) measured learning curves for deep networks in machine translation, language modeling, image classification and speech recognition. Generalization error followed power laws ε(n)≈αnβg\varepsilon(n)\approx\alpha n^{\beta_g} in every domain, with exponents usually between −0.07-0.07 and −0.35-0.35, much shallower than the −0.5-0.5 or −1-1 of classical theory. Better architectures and optimizers shifted the curve down without changing its exponent. They described three regions: a small-data region near best-guess error, the power-law region, and (expected, though not reached in their experiments) an irreducible-error region.

Kaplan et al. (2020) fitted language-model loss as L(D)=(Dc/D)αDL(D)=(D_c/D)^{\alpha_D} with αD≈0.095\alpha_D\approx0.095, alongside power laws in model size and compute, and Hoffmann et al. (2022) found that compute-optimal training should scale parameters and training tokens in equal proportion. These are empirical regularities over the ranges studied, not theorems; why the exponents take the values they do is an open question.

Predict before you look

A validation error behaves like b n−0.3b\,n^{-0.3} over the range you care about (the floor is negligible). By what factor must the training set grow to halve the error?

Show the answer

10 ×

Solve (n2/n1)−0.3=12(n_2/n_1)^{-0.3}=\frac12: n2/n1=21/0.3≈10.1n_2/n_1=2^{1/0.3}\approx10.1. At an exponent of 0.0950.095 the factor would be 21/0.095≈1,5002^{1/0.095}\approx1{,}500, which is why small exponents make data so expensive at scale.

python
import numpy as np
from scipy.optimize import curve_fit

def power_law(n, a, b, c):
    """Learning-curve model: an irreducible floor a plus a power-law term."""
    return a + b * n ** (-c)

def samples_needed(sizes, errors, target):
    """Fit (size, mean validation error) pairs, then solve a + b n^(-c) = target."""
    (a, b, c), _ = curve_fit(power_law, sizes, errors,
                             p0=[min(errors) / 2, 1.0, 0.5], maxfev=20000)
    if target <= a:
        return np.inf                    # the fitted floor is above the target
    return (b / (target - a)) ** (1 / c)

Measure the error at several sizes by repeated subsampling, re-tuning hyperparameters at each size (a model tuned for the full data is not the right model for a small subset). Refit on bootstrap resamples of the points to get an interval for the answer: the floor aa and exponent cc are often poorly identified, and extrapolating far beyond the largest measured size is risky.

What the curve showsDecision
validation error still falling steeply; large train–validation gapmore data is likely to pay; extrapolate the fit to price it
both curves flat and close togethermore data of the same kind will not help; change the model or the features
a bump or a plateau followed by a dropbeware of extrapolation: the curve has changed regime (double descent, a phase transition, a change in data quality)
small-data region near chancetoo few points to fit a power law; collect more before extrapolating
Viering & Loog's (2023) review concludes that learning curves are "surprisingly diverse and no universal model can be identified": treat every extrapolation as a forecast with uncertainty.

Key takeaways

  • The expected learning curve Rˉ(n)\bar R(n) belongs to a learner and a distribution. ERM's expected training error never decreases in nn; its test error need not decrease.
  • Regular parametric models: excess risk ≈\approx (parameters)/n/n, e.g. σ2p/(n−p−1)\sigma^2p/(n-p-1) for least squares and d/(2n)d/(2n) for maximum likelihood. Smooth nonparametric regression: n−2s/(2s+d)n^{-2s/(2s+d)}, the curse of dimensionality.
  • Learning curves can rise: minimum-norm least squares peaks at n≈pn\approx p (sample-wise double descent). Monotone learners exist in principle for classification.
  • Deep-learning curves follow power laws with small exponents (−0.07-0.07 to −0.35-0.35 in Hestness et al.); fitting a+bn−ca+bn^{-c} on subsamples prices more data, but extrapolation needs uncertainty estimates and fails at regime changes.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

For empirical risk minimization over a fixed class, what is guaranteed about the expected training error as nn grows?

  1. It never decreases
  2. It never increases
  3. It equals the expected test error for large nn, and is otherwise arbitrary
  4. Nothing, because ERM can be non-monotone
Show the answer

A. It never decreases

The empirical risk on n+1n+1 points is the average of n+1n+1 leave-one-out empirical risks, and the minimum of an average is at least the average of the minima, so Tˉ(n+1)≥Tˉ(n)\bar T(n+1)\ge\bar T(n). It is the test curve that can be non-monotone.

Question 2

A regression function has two bounded derivatives in d=10d=10 dimensions. Compared with a parametric model (rate 1/n1/n), how much more data does an optimal nonparametric method need to halve its squared error?

  1. The same: 2× in both cases
  2. About 2.4× instead of 2×
  3. About 11× instead of 2×
  4. About 100× instead of 2×
Show the answer

C. About 11× instead of 2×

The minimax exponent is 2s/(2s+d)=4/14≈0.292s/(2s+d)=4/14\approx0.29, so halving needs 21/0.29≈112^{1/0.29}\approx11 times more data. The parametric rate needs only twice as much.

Question 3

With pp isotropic Gaussian features and minimum-norm least squares, where does the sample-wise learning curve peak?

  1. At n≈p/2n\approx p/2
  2. At n≈pn\approx p, where the design matrix is nearly singular
  3. At n≈2pn\approx2p
  4. It has no peak: the curve is monotone in nn
Show the answer

B. At n≈pn\approx p, where the design matrix is nearly singular

Both variance formulas, σ2n/(p−n−1)\sigma^2n/(p-n-1) and σ2p/(n−p−1)\sigma^2p/(n-p-1), diverge as n→pn\to p: the smallest singular value of XX approaches zero and the pseudo-inverse amplifies the noise.

Question 4

According to Hestness et al. (2017), what did better architectures and optimizers do to deep-learning learning curves in a given domain?

  1. They steepened the power-law exponent
  2. They removed the power-law region entirely
  3. They shifted the curve down without changing its exponent
  4. They made the curve non-monotone
Show the answer

C. They shifted the curve down without changing its exponent

Models for a single domain showed the same steepness; improvements moved the intercept. So better models help by a constant factor at every size, while the exponent sets how expensive further error reductions are.

Further reading

  • T. Viering & M. Loog, "The shape of learning curves: a review," IEEE Transactions on Pattern Analysis and Machine Intelligence 45(6), 7799–7819 (2023).
  • C. J. Stone, "Optimal global rates of convergence for nonparametric regression," Annals of Statistics 10(4), 1040–1053 (1982).
  • J. Hestness, S. Narang, N. Ardalani, G. Diamos, H. Jun, H. Kianinejad, M. M. A. Patwary, Y. Yang & Y. Zhou, "Deep learning scaling is predictable, empirically," arXiv:1712.00409 (2017).
  • J. Kaplan, S. McCandlish, T. Henighan, T. B. Brown, B. Chess, R. Child, S. Gray, A. Radford, J. Wu & D. Amodei, "Scaling laws for neural language models," arXiv:2001.08361 (2020).
  • O. Bousquet, S. Hanneke, S. Moran, R. van Handel & A. Yehudayoff, "A theory of universal learning," Proceedings of the 53rd ACM Symposium on Theory of Computing (STOC), 532–541 (2021).