Foundations

Why the Assumption of Independent, Identically Distributed Data Matters

Learn what the i.i.d. assumption promises, how groups, time and drift break it, and which splits and checks protect your results.

Key takeaways

  • Held-out evaluation, standard error bars and classic learning bounds all lean on independent, identically distributed data.
  • Related examples, such as repeated records from one person, carry less information than their row count suggests.
  • Time order, feedback loops and changing populations break the "identically distributed" half.
  • The split should imitate deployment: by group for new groups, by time for the future.
  • Compare training and live data regularly, and treat a detected difference as a prompt to investigate.

The i.i.d. assumption says your examples are independent draws from one fixed probability distribution, and that the data you will face later come from that same distribution. It is what allows a score measured on held-out data to speak for future performance. When it fails, a model can test beautifully and then disappoint in use.

"Independent" means that knowing one example tells you nothing extra about another. "Identically distributed" means every example is generated by the same process, with the same probabilities.

What depends on it

Suppose you measure an error rate on 1,000 held-out examples. If they are independent draws from the deployment distribution, the average is an unbiased estimate of the true error and its uncertainty shrinks like 1/√n. Both statements can fail without the assumption.

The same applies to:

  • bounds in PAC learning, which require training and future examples from one distribution;
  • ordinary cross-validation, which treats folds as interchangeable;
  • mini-batch training with shuffling, where each batch is meant to resemble the whole;
  • the common formulas for confidence intervals and significance tests.

The learning algorithm itself will run on any table. Nothing warns you that the assumption has failed.

A weaker idea, exchangeability, only requires that the order of examples carries no information: any reordering is equally probable. Some methods, including conformal prediction, need only this.

Two halves of the assumption and how each can fail
Both hold Random split estimates well Dependence Groups or repeats; use grouped splits Distribution changes Time or new sites; test on them Both fail Drifting series; validate forward Both hold Random split estimates well Dependence Groups or repeats; use grouped splits Distribution changes Time or new sites; test on them Both fail Drifting series; validate forward

When examples are not independent

Common sources of dependence include several images of one patient, many clicks from one user, sentences from one document, readings from one sensor, and augmented copies of one original.

The damage comes in two forms. In evaluation, a random split places siblings on both sides, so the model is rewarded for recognizing the person, device or document. In estimation, your error bars are too narrow.

A useful approximation for equally sized clusters is the design effect:

design effect = 1 + (m − 1)·ρ        m = examples per group
effective n   = n / design effect    ρ = correlation within a group

Say you have 10,000 images from 100 patients, 100 per patient, and the within-patient correlation of the quantity you are averaging is 0.2. The design effect is 1 + 99 × 0.2 = 20.8, and the effective sample size is about 481. You have far closer to 500 independent pieces of information than 10,000.

This formula is for estimating an average. It is a guide to scale and not an exact count for every model.

A demonstration

Here each of 50 "people" contributes 20 rows. Features identify the person, and each person's label is random, so nothing generalizes to new people.

import numpy as np
from sklearn.model_selection import GroupKFold, KFold, cross_val_score
from sklearn.neighbors import KNeighborsClassifier

rng = np.random.default_rng(0)
groups = np.repeat(np.arange(50), 20)                  # shape (1000,)
centers = rng.normal(size=(50, 5))
X = centers[groups] + rng.normal(0, 0.1, (1000, 5))    # shape (1000, 5)
y = rng.integers(0, 2, 50)[groups]                     # one label per person

model = KNeighborsClassifier(5)
for cv in [KFold(5, shuffle=True, random_state=0), GroupKFold(5)]:
    print(cross_val_score(model, X, y, cv=cv, groups=groups).mean())

Shuffled folds report near-perfect accuracy. Grouped folds report nothing better than guessing, which is the truth for a new person. Group-aware splits covers more cases.

When the distribution moves

The second half fails when the data-generating process differs between training and use.

Kind of change What differs Hypothetical example
Covariate shift Distribution of inputs x A new camera changes image color
Label shift Class frequencies of y A disease becomes more common in a season
Concept shift Relationship between x and y Fraud tactics change
Selection effects Which cases get observed Outcomes known only for approved loans

The definitions assume something else stays fixed; for example, covariate shift keeps p(y | x) unchanged. Shift types are defined here in more detail. Real changes are often mixtures.

Feedback loops are a special case. A recommender shows items, users click what they see, and the next model trains on those clicks. The model's own choices shape its future data.

Correcting a change in class frequency

Some shifts can be corrected with arithmetic, if you are willing to state the assumption. Say you trained on a balanced sample, half positives, but in deployment only 10% of cases are positive. Assume the distribution of inputs within each class is unchanged, and that the model's probabilities are well calibrated on the training mix.

The odds of an event are p/(1 − p). Under these assumptions, you multiply the model's odds by the ratio of new prior odds to old prior odds.

model output          p = 0.8        odds = 0.8/0.2 = 4
old prior odds        0.5/0.5 = 1
new prior odds        0.1/0.9 ≈ 0.111
corrected odds        4 × 0.111 ≈ 0.444
corrected probability 0.444/1.444 ≈ 0.31

A prediction that read as "80% likely" becomes about 31% in the deployment population. The ranking of cases does not change, but any fixed threshold now behaves very differently.

If the inputs within a class have changed too, for instance because mild cases are now more common among the positives, this correction is not enough. Collect labeled data from the new setting and check.

Time series

Observations close in time tend to resemble one another. A random split lets a model peek at neighbors on both sides of each test point, which is far easier than forecasting.

For a series in which each value correlates with the previous one at ρ, in the simplest autoregressive form, the effective sample size for estimating the mean is about n·(1 − ρ)/(1 + ρ) when n is large. With ρ = 0.8, that is one ninth of n.

Use splits that always train on the past and test on the future, and leave a gap if features or labels span a window of time. See why shuffled cross-validation breaks on time series.

Selection decides what you see

A sample can consist of perfectly independent draws and still come from the wrong distribution. Many data sets are filtered before you receive them.

A lender observes repayment only for loans it approved. A support team labels only tickets that were escalated. A study of images collects scans from patients whom a doctor chose to refer. In each case, the model learns the relationship among selected cases and is then asked about all of them.

More data from the same filter does not repair this. The remedies involve changing what is observed, for example by labeling a small random sample of all cases, or modeling the selection process with explicit assumptions. Where decisions affect people, such as in credit or hiring, treat this as a fairness and legal question as well as a statistical one, and get qualified advice.

How to check

  1. Draw the data's history. Who or what produced each row, when, and through which filter?
  2. Count shared identifiers across your splits, including near-duplicate content.
  3. Compare scores across split schemes. A large drop from random to grouped or time-based splitting reveals dependence or drift.
  4. Plot errors and feature summaries over time and across sites.
  5. Train a classifier to tell training rows from recent rows. If its AUC stays near 0.5, it found little difference; well above that, inspect which features it uses. This is often called adversarial validation.

No test proves data are i.i.d. A passing check only means that this particular probe found nothing.

What to do when it fails

Match the evaluation to the claim. To predict for new hospitals, hold out entire hospitals. To predict next month, hold out later months.

For training, you can weight examples to correct known sampling differences, favor recent data when relationships drift, add group identifiers where deployment will see the same groups again, or retrain on a schedule. For uncertainty, resample whole groups instead of rows in a bootstrap, and use block methods for time series.

Be explicit about what you cannot cover. A model evaluated on adults from one region has not been shown to work on children or elsewhere. In medical, hiring or lending settings, such claims need proper validation and expert and legal review.

After release, keep watching. Log summaries of incoming features and predictions, and compare them with the training period. When true labels arrive, even late, track error on them directly, since a change in the link between x and y can be invisible in the inputs alone. Drift detection tests can flag changes, but you still have to judge whether a flagged change matters for performance.

Shuffling deserves a note. Shuffle the training data before mini-batching so batches look alike. Do not shuffle across the boundary that separates past from future or one group from another.

Common questions

Is any real data set truly i.i.d.?

Rarely in a strict sense. The question is whether departures are large enough to change your conclusions.

Does more data fix dependence?

More independent groups help. More rows from the same groups help much less, as the design effect shows: with ρ = 0.2, the effective size per group can never exceed 1/ρ = 5.

Are there methods that do not need the assumption?

Online learning with adversarial sequences and methods for specific kinds of shift relax parts of it. Each replaces it with other assumptions or a more modest goal.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 42 articles in Foundations →

Latest news on this topic