MolBasis
data-leakagerandom-splitscaffold-splitnear-duplicates5 min read

Random splits and leakage, how near-duplicates inflate metrics

A random split puts near-identical molecules on both sides, so the model scores on memory. Here is how large the effect is and how a scaffold split avoids it.

Updated November 28, 2026

A random split of a property dataset places near-identical molecules on both sides of the line. The test molecule then has a twin in training with a nearly identical property value, and the model scores by recalling that value rather than by predicting from chemistry. The inflation is not a rounding error. On a dataset built from analogue series, a random-split r can be far above what the same model achieves on a new scaffold. A grouped split, by scaffold or by molecule, removes the twin and shows the true figure.

Where the near-duplicates come from

Property datasets are not random samples of chemical space. They are the union of many small studies, each of which measured a series of close analogues, often a methyl, chloro or methoxy scan around one core. ESOL, the Bradley melting-point set and the solvation databanks all contain such series. Several entries can also describe one molecule. A free acid and its sodium salt, two tautomer drawings, a racemate and one enantiomer, or the same compound measured in two laboratories, all land in the file as separate rows.

For a model that uses descriptors from one DFT calculation per molecule, as the descriptor files from mfsig do, two close analogues have nearly identical descriptor vectors. The predicted values are then nearly identical too. If the twin's measured value is in the training set, the prediction for the test member is right for the wrong reason.

How much a random split leaks, in numbers

Take 1000 molecules of which 400 form 200 pairs of close analogues, meaning a Tanimoto similarity of 0.85 or more on ECFP4, the usual cut-off. Hold out 20 percent at random.

The expected number of test molecules that belong to a pair is 400 × 0.2 = 80. For each of them, the probability that the twin landed in training is about 0.8. So about 64 of the 200 test molecules, roughly a third, have a near-twin in training. For a flexible model those 64 molecules are predicted almost perfectly, and the overall test r and MAE are pulled up by a third of the set.

The same arithmetic applies to repeated measurements of one molecule. If a molecule has two rows and the split is random, the probability that the rows are separated is 2 × 0.8 × 0.2 = 0.32. One row in three ends up being predicted from its own duplicate.

import numpy as np
from sklearn.model_selection import train_test_split, GroupShuffleSplit
rng = np.random.default_rng(0)
groups = np.repeat(np.arange(500), 2)       # 500 molecules, 2 rows each
idx = np.arange(1000)
tr, te = train_test_split(idx, test_size=0.2, random_state=0)
leaked = np.isin(groups[te], groups[tr]).mean()    # about 0.8 of test rows have a twin in train
gss = GroupShuffleSplit(n_splits=1, test_size=0.2, random_state=0)
tr_g, te_g = next(gss.split(idx, groups=groups))
print(leaked, np.isin(groups[te_g], groups[tr_g]).mean())   # second value is 0.0

The symptoms a reader can spot

Three symptoms point to leakage even when the split is not described. The held-out figure is almost as good as the in-sample figure. The error distribution has a sharp spike near zero on top of a broad base, where the spike is the twins. And a nearest-neighbour baseline, predicting each test molecule from its most similar training molecule, does nearly as well as the model.

Sheridan showed in 2013 that random cross-validation on medicinal chemistry data gives figures that a realistic time-split does not reproduce. The time split puts later compounds in the test set, which is how a model is actually used. The guide on scaffold-blind versus time split compares the two remedies. For public property datasets without dates, the scaffold split is the practical choice.

Grouping before splitting

The fix is to split groups rather than rows. Three grouping rules cover most cases. Group by InChIKey connectivity block, the first 14 characters, so that salts, tautomer drawings and repeated measurements of one molecule stay together. Group by Bemis-Murcko scaffold, so that an analogue series stays together. Or cluster by fingerprint similarity at a cut-off such as 0.85 Tanimoto on ECFP4.

The MolBasis methodology uses the scaffold rule. It sets aside 25 percent of unique Bemis-Murcko scaffolds, with one seed, before any equation is searched or any coefficient is fitted. The record's rigor gate adds a grouped leave-one-out by molecule on the InChIKey first block. The step-by-step guide on the scaffold split shows how to build the groups with RDKit, and the guide on grouped cross-validation covers the molecule-level rule.

Grouping has a cost. A scaffold-blind held-out set is harder, so the figures are lower than a random split would give, and because 25 percent of scaffolds is not 25 percent of molecules, the held-out set can be small. Each kernel page states how many held-out molecules its figures rest on. Lower and honest beats higher and leaked.

Leakage that survives a scaffold split

Grouping by scaffold does not catch everything. Two molecules with different scaffolds can share a measured value because one entry is a transcription of the other. Descriptor definitions tuned on the full dataset leak through the model form rather than through the rows. And the choice to remove an outlier after seeing full-data residuals leaks the test set's information into the training decision.

The guide on duplicates and conflicting measurements covers how to find repeated entries before splitting. Dataset cleaning, grouping and splitting belong in one script that runs before any model is fitted, and that script belongs in the record.

Key points

  • Property datasets are unions of analogue series and repeated measurements, so random splits separate twins.
  • With 200 analogue pairs in 1000 molecules and a 20 percent random test set, about a third of the test set has a twin in training.
  • Symptoms are a tiny in-sample to held-out gap, a spike of near-zero errors and a strong nearest-neighbour baseline.
  • Group by InChIKey block, Bemis-Murcko scaffold or similarity cluster before splitting. MolBasis groups by scaffold.
  • A grouped split gives lower figures and smaller held-out sets. Report the molecule count with the figures.

Questions people ask

What is data leakage in QSPR?
Leakage is any path by which information about a test molecule's property reaches the model before it is tested. The commonest path is a close analogue, a salt form or a repeated measurement of the same molecule in the training set. The model then reproduces a remembered value and the test score overstates predictive power.
How does a random split cause leakage?
Property datasets contain series of close analogues and often several entries for one molecule. A random split assigns each entry independently, so most pairs end up with one member on each side. The test member is then predicted from its twin rather than from chemistry.
What is the fix for leakage from near-duplicates?
Group entries before splitting so that a whole group goes to one side. Grouping by Bemis-Murcko scaffold, by InChIKey connectivity block or by a Tanimoto similarity cluster all work. The MolBasis protocol groups by scaffold and sets aside 25 percent of scaffolds before any fitting.

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.