A classifier can score 100% on held-out measurements without learning anything that transfers to a new biological source. The clue is in what you held out: a row is not necessarily an independent sample.
Split on the unit you expect to be new at deployment, such as donor, cell line, experiment, plate, or site. If the same source appears in training and testing, a model may recognise the source instead of learning a signal that generalises.
How can 100% balanced accuracy be misleading?
We simulated 60 source groups with five measurements per source (300 rows total). Each source had a distinct fingerprint across eight numeric features and a randomly assigned class. A one-nearest-neighbour classifier can match very similar measurements. There is no designed rule connecting fingerprints to class on unseen sources.

Using the same data and classifier, we held out 75 rows two ways: a stratified random row split and a group-aware split holding out 15 entire sources. We calculated balanced accuracy as the mean of recall for class 0 and class 1. No dataset was downloaded; no clinical or biological claim follows from this example.
| Test design | Shared sources | Balanced accuracy |
|---|---|---|
| Random rows | 44 | 100% |
| Unseen sources | 0 | 33% |


Every random-split test row had its nearest training neighbour from the same source. In the group split, none did. The 33% result came from one seed and one particular set of groups; it illustrates unstable performance on unseen sources, not a general benchmark or evidence of a reliably below-chance model.


Which column should be the group?
- Predict a new donor: group every aliquot, visit and technical replicate by donor.
- Predict a new lab or site: hold out entire sites or use an independent site. Donor isolation alone does not test site transfer.
- Predict a later time period: respect time order. Grouping alone does not make a random split prospective.
If multiple relationships overlap, no single grouping column may satisfy every requirement. Document the intended prediction task and audit the split for the relationships that matter before choosing an evaluation design.
What should you check before training?
- Keep a source ID in the sample sheet and calculate the train/test intersection. It should be empty for the isolation criterion you chose.
- Count both groups and rows per class in each partition. A group-aware split can still produce uneven classes. Don’t silently select the split with the best score.
- Fit scaling, imputation and feature selection only on each training fold. Keep your final test set out of tuning.
- Save the assigned source IDs, software version and scoring rule. If your claim is about new sources, report performance and uncertainty at that level where appropriate.
from sklearn.model_selection import GroupShuffleSplit
splitter = GroupShuffleSplit(n_splits=1, test_size=0.25, random_state=17)
train, test = next(splitter.split(X, y, groups=source_id))
assert set(source_id[train]).isdisjoint(source_id[test])source_id is a NumPy array aligned with the rows of X. The quarter in this example refers to groups, not rows; the row counts match only because all groups are equal-sized.
FAQs
Is a stratified row split enough? No. Stratification can balance labels while still spreading repeated measurements from the same source across partitions.
Is one group split enough for a paper? Not necessarily. Depending on the claim and the number of groups, use group-aware cross-validation and, where feasible, a truly independent test set. Report how many independent sources were available.
References and related reading
- scikit-learn: GroupShuffleSplit
- scikit-learn: Cross-validation and grouped data
- scikit-learn: Common pitfalls and data leakage
- BMB-UOG: Diagnosing Nextflow cache misses
Reviewed 4 December 2026. All figures are original Python-generated outputs from the described, seeded simulation. Model: scikit-learn 1.8.0.
0 Comments
We will get back to you as soon as possible and thanks for the comment.