Finished ·

Make your Statistics Sound with this One Cheap Trick

Cross-posted to Substack.

If you don’t want to be fooled by randomness, and you don’t want to think too hard, you should be using the ✨bootstrap ✨.

Image
Thank you for keeping our inferences sound, Black Swan Man. (credit: @black_swan_man on X)

Machine learning papers typically have bad statistical methods. The numbers don’t even have confidence ranges, or the plots don’t have error bars. For example, even though the NeurIPS 2025 checklist requires error bars, the first paper I clicked from the list of accepted papers has no error ranges in table 1. The field of ML makes progress despite bad statistics, because replication is so easy, so why bother?

I think it does matter, because replicating papers still has a cost, and giving accurate information to readers is important. Nevertheless, you can make a self-interested argument for using sound statistics: during hyperparameter/algorithm search. When getting a ML idea to work, you typically try lots of different variations. Often each variation just has 1-3 seeds. Being able to compare the error bars on each of these leads to better decisions about what to cut and what to keep.

Here’s how to use the bootstrap. If your measurement is summarized from N samples, you can pass the samples and the summary function directly to scipy.stats.bootstrap, and it will give you a 95% confidence interval for your measurement. You can use these as error bars. Hooray!

Under the hood, the bootstrap method samples many times with replacement from your dataset, and then computes the summary statistic for each sample. This gives you a distribution of likely values of your summary statistic. For example, suppose you have 100 samples and are computing the mean of your quantity. The bootstrap will sample 10,000 times a set of 100 samples with replacement, and compute its mean. You get a distribution of possible means.

How well does it work?

The Bootstrap is a consistent estimator of your confidence interval of interest. Concretely, as your number of observed samples N grows to infinity, the probability of the true value falling inside the 95% interval computed approaches 95%. (Of course, if we’re talking about means, the interval gets narrower and narrower with larger N too.)[1] In fact, it can be shown that, for the bias-corrected method scipy uses, the error in probability between the requested interval coverage and the actual percentage of time it covers the true value decays as O(1/n).

For comparisons, computing ranks is better than values

For example, say you have 10 different variations of an algorithm, you want to compare them.

You could compute the per-datapoint accuracy to bootstrap, then compute the 95% confidence interval for the average accuracy, and check if these intervals overlap. This gives you a great idea of what the accuracy is. But in cases where the accuracy of the variations is close, it needs a lot of samples to tell you which one is better. The intervals will almost always overlap. (This is kind of conservative, strictly speaking hypothesis tests can do better.)

Alternatively, you can compute the ranking of each method on each data point. The average ranking for each algorithm is also a quantity for which the bootstrap can give confidence intervals! Because it doesn’t depend on how much better each algorithm is, and it takes into account that only one algorithm can be ‘the best’ at any particular data point, it often needs many fewer data points to conclude one algorithm is decisively better than another.

Bootstrap estimation thus gives us a very easy way to get error bars, and to make a 10-treatment version of the McNemar test.


  1. Interestingly, the Bootstrap wikipedia page has a section on Gaussian process regression for bootstrapping data with temporal correlations, which cites a single article. I’m 85% sure that it was written by the author of that article. I’m pretty sure that is only correct if your measurements are Gaussian distributed. In fairness, if you’re measuring means of independent data points, they kind of are Gaussian. ↩︎