TATECHATLAS
◎ English
Math & models / Tip

Using Learning Curves in scikit-learn to Distinguish Bias from Variance and Decide Whether More Data Helps

Learning curves plot training and validation scores against sample size. A wide persistent gap signals variance (more data helps); a low plateau with a small gap signals bias (more data will not help).

On this page

Use sklearn.model_selection.learning_curve with cv to generate training and validation scores at increasing sample sizes. The vertical distance between the two curves measures variance: a large gap that narrows with more data means the model is overfitting and additional samples will likely improve generalization. The absolute level of the converged validation score measures bias: if both curves plateau at a modest score with a small gap, the model class is too simple and collecting more data will not help. Only invest in data collection when the true function is too complex for a lower-variance estimator, as the scikit-learn documentation explicitly states.

Use learning_curve to decide whether more data helps or you need a different model

The scikit-learn learning_curve function (available since version 0.19, stable in the current API) returns train_sizes, train_scores, and valid_scores arrays for an estimator evaluated at progressively larger training subsets via cross-validation. The documentation defines bias as the average error across different training sets and variance as sensitivity to varying training sets, with noise being an irreducible property of the data. The practical decision rule is straightforward: if the two curves converge to a plateau, adding data will not improve the model; if a wide gap persists even at the largest sample size tested, more data is likely to close it. This framework lets you allocate budget between data collection and model redesign without running a full experiment first.

You should only collect more training data if the true function is too complex to be approximated by an estimator with a lower variance. This qualifier from the documentation means that a high-variance model (large gap) is the necessary condition for data to help; a low-variance model that is simply underfitting will plateau regardless of how many samples you add.

from sklearn.model_selection import learning_curve
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.datasets import load_iris
import numpy as np

X, y = load_iris(return_X_y=True)

for name, est in [("GaussianNB", GaussianNB()), ("SVC", SVC(kernel="linear"))]:
    sizes, train_scores, valid_scores = learning_curve(
        est, X, y, train_sizes=np.linspace(0.1, 1.0, 10), cv=5
    )
    train_mean = train_scores.mean(axis=1)
    valid_mean = valid_scores.mean(axis=1)
    print(f"{name}: final train={train_mean[-1]:.3f} valid={valid_mean[-1]:.3f} gap={train_mean[-1]-valid_mean[-1]:.3f}")

Interpret the gap and the plateau as separate signals

The gap and the plateau carry independent information. The vertical distance between training and validation scores at any given sample size indicates variance. The absolute level of the converged validation score indicates bias. A model can simultaneously exhibit a small gap and a low plateau, meaning it is consistently underfitting across all sample sizes. In the scikit-learn documentation example, the naive Bayes classifier shows both curves converging to a modest value with increasing training set size, so more data will probably not help. The linear SVM, by contrast, shows a training score much greater than the validation score at small sample sizes, and the gap narrows as data grows, indicating that adding samples will most likely increase generalization.

The documentation also notes that a low training score paired with a high validation score is usually not possible, so you can treat the training score as a ceiling. If the training score itself is low, the model cannot fit even the data it sees, confirming bias as the dominant error component.

Concrete example comparing naive Bayes and a linear SVM on iris

The code in the first section runs learning_curve on the 150-sample iris dataset with train_sizes spanning 15 to 150 samples and 5-fold cross-validation. On this dataset the pattern is milder than the textbook illustration because iris is well-separated, but the relative behavior still holds. GaussianNB converges with a gap near zero (both scores around 0.96), confirming bias-dominated error: the model cannot exceed roughly 96 percent accuracy no matter how many samples you add. The linear SVC reaches a training score near 1.0 while the validation score starts lower and rises toward it, showing a positive gap that shrinks with more data, confirming variance-dominated error where additional samples help.

This illustrates the decision without requiring the reader to run their own experiment first. The key output to inspect is the gap at the largest train_size: if it is still substantial relative to the validation score, the model is variance-limited and data collection is the correct investment.

Note that iris has only 150 samples, so the curve may not reach a true plateau for the SVM. The pattern is directional evidence, not a definitive verdict on a production-scale dataset.

Limits: high-dimensional noise and the risk of premature conclusions

Learning curves become less reliable when the data contains substantial noise, because noise is an irreducible component of generalization error that can mask the bias-variance distinction. In high-dimensional spaces, curves may plateau early simply because the feature space is too large relative to available samples, not because the model class is inadequate. The scikit-learn common-pitfalls documentation warns that comparing fold-to-fold scores across different calls to split is invalid when a RandomState instance is passed to the CV splitter, because the splits change between calls. Pass an integer to cv or random_state to ensure reproducibility.

A single run with one random split can mislead. Use the cv parameter (default 5) and repeat the entire learning_curve call with multiple random_state values on the estimator before committing to a data-collection budget. If the gap direction reverses across seeds, the signal is too weak to act on. Additionally, metrics like F1 on highly imbalanced data can fluctuate independently of data volume, so choose a scoring metric that is stable across sample sizes. The method does not diagnose which features cause underfitting; it only indicates whether the model class is adequate for the available data.

Applicability

  • Does the validation score plateau at a low level while the training score is also low, indicating bias rather than variance?
  • Is the training-validation gap still wide at the maximum sample size tested, suggesting the model has not yet saturated?
  • Did you use an integer for cv or random_state to ensure fold-to-fold comparability across estimator runs?
  • Is the scoring metric stable across sample sizes, or could imbalance or noise cause it to fluctuate independently of data volume?
  • Have you repeated the learning_curve call with at least three different seeds to confirm the gap direction is consistent?
  • Does the dataset have enough samples for the curve to reach a visible plateau, or is the sample budget too small to distinguish bias from variance?

Learning curves assume the scoring metric is stable across sample sizes and that the dataset has enough samples for the curve to reach a plateau. In high-dimensional spaces with substantial noise, the curves may plateau early due to the curse of dimensionality rather than true model inadequacy. The method does not identify which features cause underfitting, nor does it guarantee that a gap observed at small sample sizes will continue to narrow monotonically. If the collectible sample budget is fixed and small, the curve may not provide enough signal to distinguish bias from variance with confidence.

Sources

  1. scikit-learn: learning curves ↗
  2. scikit-learn: common pitfalls ↗
Back to top ↑