MolBasis
bootstrapconfidence-intervalmaepearson-r5 min read

Bootstrap confidence intervals for Pearson r and MAE

A bootstrap interval resamples held-out molecules with replacement and recomputes the figure. On eight molecules the interval for MAE spans a factor of three.

Updated November 28, 2026

A bootstrap confidence interval resamples the held-out molecules with replacement, recomputes the figure on each resample, and reads the interval from the spread of the results. It needs no formula for the standard error of r or MAE and no assumption about the error distribution. For a held-out set of eight molecules, the 95 percent interval for MAE typically spans a factor of three, which is the main reason a point figure on a small set should never be read alone. The MolBasis record lists bootstrap intervals among its gate checks, and the held-out figure shown on each kernel page comes without one.

The idea in one paragraph

Efron introduced the bootstrap in 1979. The held-out set is treated as the best available picture of the population of molecules the model will meet. Drawing from it with replacement, as many times as it has rows, produces a new set of the same size in which some molecules appear twice and others not at all. The statistic is recomputed on that set. Repeating this a few thousand times gives the distribution the statistic would have had if the held-out set had been drawn again from the same population. The 2.5th and 97.5th percentiles bound a 95 percent percentile interval.

A worked example on eight errors

Suppose the held-out absolute errors are 0.2, 0.5, 0.1, 0.9, 0.3, 0.4, 1.2 and 0.6. Their sum is 4.2, so the MAE is 4.2 / 8 = 0.525.

Draw one resample by index, say positions 1, 1, 3, 4, 6, 6, 7 and 2. The values are 0.5, 0.5, 0.9, 0.3, 1.2, 1.2, 0.6 and 0.1, summing to 5.3, and the resampled MAE is 5.3 / 8 = 0.6625. Draw another, positions 0, 2, 2, 4, 5, 0, 1 and 3. The values are 0.2, 0.1, 0.1, 0.3, 0.4, 0.2, 0.5 and 0.9, summing to 2.7, and the MAE is 0.3375. Two resamples, one at 0.66 and one at 0.34, from a point figure of 0.525.

A rough check uses the standard error of the mean. The eight errors have mean 0.525 and deviations −0.325, −0.025, −0.425, 0.375, −0.225, −0.125, 0.675 and 0.075. The squared deviations sum to 0.955, dividing by 7 gives 0.136, and the standard deviation is 0.369. The standard error is 0.369 / √8 = 0.131, so a normal approximation gives 0.525 ± 0.26, about 0.27 to 0.78. The bootstrap percentile interval will land near this, slightly asymmetric because the largest error cannot be resampled into a negative one. A factor of three between the lower and upper bound, on eight molecules.

import numpy as np
e = np.array([0.2, 0.5, 0.1, 0.9, 0.3, 0.4, 1.2, 0.6])
rng = np.random.default_rng(2026)
boot = np.array([np.abs(rng.choice(e, size=e.size, replace=True)).mean()
                 for _ in range(4000)])
lo, hi = np.percentile(boot, [2.5, 97.5])
print(round(e.mean(), 3), round(lo, 3), round(hi, 3))

Bootstrapping Pearson r

For r, resample pairs. Each resample picks the same indices for measured and predicted values, so the pairing is preserved, and r is recomputed on the resampled pairs. Two warnings apply. A resample can contain only two distinct molecules if the set is tiny, and r is then meaningless or undefined, so drop resamples with fewer than three distinct values. And r is bounded at 1, so the percentile interval is asymmetric and a normal approximation around the point value is wrong near the top of the range. The guide on small test sets and unstable figures gives the Fisher transformation as the parametric alternative and shows that r = 0.80 on eight molecules has a 95 percent interval from about 0.22 to 0.96.

def boot_r(y, yhat, n_boot=4000, seed=2026):
    rng = np.random.default_rng(seed)
    out = []
    for _ in range(n_boot):
        idx = rng.integers(0, y.size, y.size)
        if np.unique(y[idx]).size < 3:
            continue
        out.append(np.corrcoef(y[idx], yhat[idx])[0, 1])
    return np.percentile(out, [2.5, 97.5])

What the bootstrap cannot do

It cannot see molecules that are not in the held-out set. If all eight held-out molecules share a scaffold, no resampling of them says anything about other scaffolds. It cannot repair a leaked split. A bootstrap interval around a figure inflated by near-duplicates is a tight interval around the wrong number. And on very small sets it is unstable itself, because the resamples are recombinations of the same handful of values. With eight molecules there are only 6435 distinct resamples, and the interval's endpoints jump when one error is changed.

The bootstrap also addresses only one source of uncertainty, the draw of molecules within a fixed split. The draw of the split itself, meaning which scaffolds were held out, is a second source, treated in the guide on the one-seed, one-split problem. A complete picture needs both.

Intervals in the MolBasis record

The MolBasis methodology lists bootstrap 95 percent intervals on r and MAE among the checks of its rigor gate, next to the permutation floor and the nested cross-validation. The final held-out figures reported on each kernel page come from one scaffold-blind split with one seed, and the record holds no confidence interval for them. Each page states the number of held-out molecules instead, and that count is the reader's guide to how wide an interval would be. Where the count is small, the figure should be read as the worked example above suggests, as a point inside a wide range.

For the separate blind benchmark, per-molecule predictions exist and the statistics were recomputed, so an interval can be computed by anyone with the predictions. The guide on recomputing statistics from stored predictions shows the steps.

Key points

  • Resample the held-out rows with replacement, recompute the figure, repeat thousands of times, and read the 2.5th and 97.5th percentiles.
  • On eight molecules an MAE of 0.525 has a 95 percent interval of roughly 0.27 to 0.78, a factor of three.
  • For r, resample pairs, drop degenerate resamples and expect an asymmetric interval near 1.
  • The bootstrap sees only the molecules it is given. It cannot repair leakage or speak for unseen scaffolds.
  • MolBasis kernel pages state the held-out molecule count and no interval. Read a small count as a wide interval.

Questions people ask

How do I compute a bootstrap confidence interval for MAE?
Take the held-out absolute errors, draw a sample of the same size with replacement, compute its mean, and repeat a few thousand times. The 2.5th and 97.5th percentiles of those means form a 95 percent percentile interval. The same recipe applies to Pearson r by resampling pairs of predicted and measured values.
Why does a held-out figure need a confidence interval?
The figure depends on which molecules happened to land in the held-out set. With few molecules a single large error or a single well-predicted outlier moves the figure a lot. The interval tells the reader how much, and a wide interval is a warning that the point value is not a stable property of the model.
Does the bootstrap work on very small held-out sets?
It runs, but it can only see the values it was given. With eight molecules the interval is wide and itself uncertain, because the resamples recombine the same eight errors. Treat it as a rough indication of instability rather than an exact statement.

Further reading

In practice: The methodology page describes the checks applied to every kernel, scaffold-blind split included, and the limits of those checks. Every kernel page quotes the held-out figure first and the in-sample figure second.

See the kernels themselves

Every kernel is shown with its held-out result, the number of molecules it rests on and what it cannot be trusted for.