AI Wiki中文/EN

Learning curves: read the axis and the spread

学习曲线

Enumerate train/validation splits, derive exact mean errors and distinguish split variation from confidence.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

What does the horizontal axis measure?

Two charts may both be called learning curves while answering different questions. Loss against optimizer steps asks whether a fixed training run is progressing. Error against the number of training examples asks whether a procedure benefits from more data. Error against a hyperparameter is a validation curve. Label the axis before diagnosing the model.

The scikit-learn guide, Section 3.5.2 uses training-set size for learning curves. Its learning_curve API evaluates training subsets across validation splits and returns the split-level scores. We use an exhaustive small dataset to see what those averages conceal.

A constant predictor makes the averages calculable

Take a finite population of N=8 labeled observations with targets (−3,−2,−1,0,0,1,2,3). A constant model predicts the mean of its n training targets. Each split S contains n distinct indices, with the remaining indices reserved for validation:

μ^S=1n∑i∈Syi,Etr(S)=1n∑i∈S(yi−μ^S)2,Eva(S)=1N−n∑i∉S(yi−μ^S)2.\widehat\mu_S=\frac1n\sum_{i\in S}y_i,\qquad E_{\rm tr}(S)=\frac1n\sum_{i\in S}(y_i-\widehat\mu_S)^2,\qquad E_{\rm va}(S)=\frac1{N-n}\sum_{i\notin S}(y_i-\widehat\mu_S)^2.

The two zero-valued observations have different indices and remain separate observations. We average uniformly over every subset of size n, rather than pretending the subsets are independent datasets. The population mean is zero and its variance with denominator N is sN²=7/2.

For general finite targets with population variance sN², uniform sampling without replacement gives:

Var⁡(μ^S)=sN2N−nn(N−1),EEtr=sN2N(n−1)n(N−1),EEva=sN2N(n+1)n(N−1).\operatorname{Var}(\widehat\mu_S)=s_N^2\frac{N-n}{n(N-1)},\qquad \mathbb E E_{\rm tr}=s_N^2\frac{N(n-1)}{n(N-1)},\qquad \mathbb E E_{\rm va}=s_N^2\frac{N(n+1)}{n(N-1)}.

To obtain the training expression, expand the squared residuals: the training second moment minus the squared training mean remains. For validation, the centered complement mean is −n/(N−n) times the centered training mean. Substitute this into the cross term and use the sample-mean variance. These identities describe this finite-population protocol, not arbitrary neural networks or an independent infinite test population.

For our targets the expected training MSE is 4(n−1)/n and validation MSE is 4(n+1)/n. The training error rises as training size increases, even though the validation average improves. That is not a broken optimizer: every constant is fitted exactly. Tiny training sets are easier for a constant to fit.

Let Kₙ be the number of enumerated subsets and Eₙ,ₖ a validation MSE. We report:

E‾n=1Kn∑k=1KnEn,k,ssplit(n)=1Kn∑k=1Kn(En,k−E‾n)2,EEva−EEtr=8n.\overline E_n=\frac1{K_n}\sum_{k=1}^{K_n}E_{n,k},\qquad s_{\rm split}(n)=\sqrt{\frac1{K_n}\sum_{k=1}^{K_n}(E_{n,k}-\overline E_n)^2},\qquad \mathbb E E_{\rm va}-\mathbb E E_{\rm tr}=\frac8n.

The last identity specializes the gap to this dataset. The split standard deviation describes the spread across our exhaustive set of splits; it is not a standard error or a confidence interval for a future population. Overlapping training and validation sets across repetitions make naive independent-replicate formulas inappropriate.

Mean training MSE rises from 0 to 10/3 while mean validation MSE falls from 8 to 14/3 as training size grows from 1 to 6.
Lines connect the enumerated means; the blue band is validation mean ± one split standard deviation. It is not a confidence interval. The band can widen while the mean improves.

Refit from scratch on every split

The complete standard-library Python 3.12 program uses exact rational arithmetic, enumerates all training subsets and refits the mean for each one. Sizes 1,2,4,6 yield 8,28,70,28 splits. Float conversion occurs only when displaying standard deviations. No validation target participates in fitting.

from fractions import Fraction as F
from itertools import combinations
from math import sqrt


def mean(values):return sum(values,F(0))/len(values)


def score(values,prediction):return mean([(v-prediction)**2 for v in values])


def split_score(values,indices):
    y=tuple(F(v) for v in values);indices=tuple(indices)
    if not 2<=len(y)<=12 or not 0<len(indices)<len(y):raise ValueError('nonempty train and validation sets required; N at most 12')
    if any(type(i) is not int or not 0<=i<len(y) for i in indices) or len(set(indices))!=len(indices):raise ValueError('unique valid integer training indices required')
    selected=set(indices);train=[y[i] for i in indices];valid=[v for i,v in enumerate(y) if i not in selected]
    fitted=mean(train)
    return fitted,score(train,fitted),score(valid,fitted)


def curve(values,sizes):
    y=tuple(F(v) for v in values);rows=[]
    if not 2<=len(y)<=12:raise ValueError('population size must be 2 to 12')
    if any(type(n) is not int or not 1<=n<len(y) for n in sizes):raise ValueError('training sizes must leave validation observations')
    for n in sizes:
        records=[split_score(y,ids) for ids in combinations(range(len(y)),n)]
        train=mean([r[1] for r in records]);valid=mean([r[2] for r in records])
        variance=mean([(r[2]-valid)**2 for r in records])
        rows.append((n,len(records),train,valid,variance))
    return rows


if __name__=='__main__':
    y=(-3,-2,-1,0,0,1,2,3)
    print('n / splits / train MSE / validation MSE / split SD')
    for n,count,train,valid,var in curve(y,(1,2,4,6)):
        print(n,count,str(train),str(valid),round(sqrt(float(var)),6))
    first=split_score(y,(0,))[2];larger=split_score(y,(0,1))[2]
    print('one nested comparison:',str(first),str(larger))
    print('fixed identity baseline MSE:',str(score([F(v)-F(v) for v in y],F(0))))

Actual output:

n / splits / train MSE / validation MSE / split SD
1 8 0 8 4.0
2 28 2 6 2.640497
4 70 3 5 2.238861
6 28 10/3 14/3 3.128424
one nested comparison: 100/7 155/12
fixed identity baseline MSE: 0

To make a useful non-AI baseline explicit, suppose each observation also has an available measurement x equal to y in this constructed dataset. The fixed rule “predict x” has zero error; the fitted constant deliberately ignores that feature. Thus a narrowing train/validation gap does not establish that a model uses the information needed for the task. This baseline is a declared data construction, not a trained model or a claim that real labels are known at inference.

Enumerating all subsets costs O(N times the sum of binomial(N,n)) here, so N is capped at 12. A realistic workflow samples a fixed set of valid splits, fits preprocessing within each training subset, refits the estimator, and stores per-split scores and fit times. Keep a final test set separate from choices made using these curves.

A curve suggests an experiment, not a verdict

A persistent gap can motivate collecting more representative data or reducing variance, but leakage, distribution shift and evaluation mistakes can produce misleading curves. High error on both sides can motivate a stronger representation or a better optimizer. It can also reflect irreducible noise. Compare the absolute scores with a meaningful baseline, not only with each other.

Use equal training budgets if studying data-size effects at a fixed compute cost; use adequately converged fits if studying statistical benefit. These are different questions, and more data at fixed epochs also means more updates. Report which condition was held fixed. A better score at a larger n is not guaranteed on every observed split, and a plateau over a short range does not establish a permanent ceiling.

For grouped observations or time series, random row splits may violate deployment conditions. Use group or temporal boundaries, avoid duplicated subjects across splits, and keep transformations within training folds. The API’s default splitter is not a substitute for deciding the sampling unit. Its test_scores during cross-validation are validation scores for model selection, not a license to reuse the final test set.

Read the numbers before the shape

  1. At n=2, what are the exact mean training and validation MSEs?

Answer 1: 2 and 6, so the gap is 4.

  1. Does increasing training error prove training failed?

Answer 2: No. In this example the optimal constant is fitted exactly at every size, and average training error still rises.

  1. Is the displayed split SD a 95% confidence interval?

Answer 3: No. It is the spread across overlapping finite-population splits, without a population-confidence claim.

  1. Can preprocessing be fitted once on all observations before drawing training subsets?

Answer 4: Generally no: learned transformations must be fitted using the relevant training subset, unless they are genuinely fixed independently of these data.

Retain the scores behind the plot

The scikit-learn sources define the data-size workflow and the split-level API contract. The finite-population identities, exhaustive implementation and missing-feature baseline are original. The program does not call scikit-learn or claim to reproduce its default folds. Continue with cross-validation, bias–variance tradeoff and neural network debugging.

Make a prediction, then check

What does the reported split standard deviation mean?

Choose one answer

Learning objectives

  • Distinguish training-time and data-size axes.
  • Report split variability without inventing confidence intervals.

Prerequisites & connections

Explore related knowledge →

References

  1. Validation curves and learning curves — scikit-learn 1.7
    scikit-learn developers
  2. learning_curve — scikit-learn 1.7
    scikit-learn developers

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.

  • Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
  • Four focused CPython3.12.4 tests passed per chapter. Bidirectional alignment/Jacobians, injected network faults, exhaustive learning curves and stochastic paths, exact momentum trajectories, Nesterov reparameterization and a smooth accelerated bound instance are checked. Bidirectional RNN/debugging use NumPy1.26.4; the other four use the standard library.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
  • Bilingual SVG learning curves generated from the executed exhaustive split scores with Matplotlib3.9.1; shaded spread is one split SD, not a confidence interval. Inspected Chinese chart; both SVGs and exact score data are hash-bound.
  • Mobile screenshot exposed small chart labels and default figure side margins. Increased chart labels and removed those margins in new formal articles only; equations, examples and exercises unchanged. Final SVG/data/article hashes rebound; frozen original draft retained.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.