Skip to content
mlmentorship

Bootstrap and resampling

Estimate uncertainty by resampling the observed units. Preserve pairing and dependence, report the resampling unit, and know when the bootstrap can fail.

Published · 7 min read ·Core ·Intermediate

Visual quick review

Visual first · depth when needed

Identify the independent sampling unit and keep every dependent observation attached to it when constructing a bootstrap replicate.

Preparing the visual…

Summary

The bootstrap estimates sampling uncertainty by repeatedly resampling observed units with replacement and recomputing a statistic. The distribution of those recomputed values approximates how the statistic would vary across new samples.

The method is useful when analytic standard errors are hard to derive. Its validity depends on the resampling unit and whether the observed sample represents the target population.

Nonparametric bootstrap

Suppose the data contains observations and the statistic is .

For each bootstrap replicate:

  1. Draw observations with replacement from the original sample.
  2. Compute the statistic on that resample.
  3. Store the result.

After replicates, the stored values approximate the sampling distribution of .

A bootstrap sample repeats some observations and omits others. Each original observation has probability

of being omitted. About 63.2% of distinct observations appear in a large bootstrap sample.

Standard error and confidence intervals

The bootstrap standard error is the sample standard deviation of the replicate statistics:

A percentile interval uses empirical quantiles of the bootstrap distribution. A 95% interval takes the 2.5th and 97.5th percentiles.

Percentile intervals are simple but can be inaccurate for biased or highly skewed estimators. Basic, studentized, and bias-corrected accelerated intervals address different errors. In an interview, explain the simple interval first and then name the limitation.

Paired model comparison

When two models score the same examples, preserve that pairing.

For each example , compute the difference

Resample the examples, then average the selected differences. This paired bootstrap keeps the correlation between model outcomes. Resampling model A and model B separately throws away useful information and usually gives a wider or incorrect interval.

For generated outputs, resample prompts and keep both models’ outputs for a prompt together. For repeated human ratings, decide whether the target population is prompts, raters, users, or a combination.

Choose the resampling unit

The independent unit may be larger than one row.

Data structureResampling unit
Independent examplesexample
Many events per useruser
Documents split into passagesdocument
Queries with many candidatesquery
Time seriestime block
Multi-seed training studyseed or complete run

If events from one user appear as independent bootstrap rows, the interval can become far too narrow. Resample the unit that could plausibly have been drawn again from the target population.

Learning objective: identify the independent sampling unit and keep every dependent observation attached to it when constructing a bootstrap replicate.

Resampling unit

If users are independent, draw users, not detached event rows.

Valid user-level bootstrap compared with invalid event-row bootstrap The source dataset contains users U1, U2, and U3, each enclosing two event rows with paired model A and B outcomes. A valid bootstrap replicate draws U3, U1, and U3, carrying both events and both model outcomes whenever a user is selected. An invalid replicate samples detached event rows from across users and is crossed out because it breaks within-user dependence. SOURCE DATA · USERS ARE THE INDEPENDENT UNITS U1 U2 U3 event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B VALID REPLICATE · DRAW U3, U1, U3 U3 U1 U3 again event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B each draw carries the whole user cluster INVALID FOR THIS DATA · DRAW DETACHED EVENTS U3 event 2 A + B U1 event 1 A + B U2 event 2 A + B breaks within-user dependence → uncertainty can look too small
Read it this way: first draw a user ID with replacement; then copy that user's entire box into the replicate. Repeating U3 is allowed and omitting U2 is allowed, but separating a user's events is not. The same rule preserves paired model outcomes: A and B stay attached to every selected event. Procedure checked against Efron's bootstrap paper, SciPy's bootstrap documentation, and Bootstrap Methods and Their Application; the graphic is original.

Block and cluster bootstrap

A cluster bootstrap samples whole groups. It preserves dependence within each group and assumes groups are approximately independent.

A block bootstrap samples contiguous time windows. It preserves short-range temporal dependence. The block length must be long enough to retain relevant correlation, but short enough to provide enough distinct blocks.

For hierarchical data, a multi-stage bootstrap can sample users first and events within selected users second. State the population that each stage represents.

Worked example

Two classifiers score the same 1,000 examples. Model B improves accuracy by 0.8 percentage points.

A paired bootstrap resamples example indices 10,000 times and recomputes the accuracy difference. Suppose the 95% percentile interval is points.

The estimate favors B, but the interval includes zero and meaningful losses. This result alone does not support a confident launch. More data or a clearer decision threshold is needed.

When the bootstrap fails

The ordinary bootstrap can fail when:

  • observations are dependent but rows are resampled independently;
  • the sample is too small to represent rare outcomes;
  • the estimator changes discontinuously near a boundary;
  • extreme values dominate a heavy-tailed statistic;
  • classes or slices absent from the sample matter in deployment;
  • the data was selected by a policy that hides unobserved outcomes.

Resampling cannot create population coverage that the original sample lacks. It only reuses observed information.

In an interview

Use this order:

  1. Name the statistic and target population.
  2. Choose the independent resampling unit.
  3. Preserve model pairing.
  4. Describe the resample-and-recompute loop.
  5. Report the effect and interval.
  6. Discuss dependence, rare events, and sample coverage.

A common follow-up asks how many replicates to use. A few thousand often estimates a standard error well; tail quantiles need more. Compute is rarely the main limit compared with choosing the right unit.

Common mistakes

  • Resampling rows when users or documents are the independent units.
  • Breaking paired comparisons.
  • Calling the bootstrap distribution a posterior distribution.
  • Reporting an interval without the effect estimate.
  • Treating resampling as a fix for biased data.
  • Ignoring seed variation in model training.

Practice next

Apply paired resampling in hypothesis testing and confidence intervals, reproducible model comparison, and paper critique.