← All writing
Evaluation · 5 min read · 9 Nov 2026

Designing a Held-Out Test Set That Resembles Deployment

A random split often lies to you about how good your model is. Here is a worked example of building a test set that tells the truth.

Cover image for the article: Designing a Held-Out Test Set That Resembles Deployment

Why the default split misleads you

The standard recipe, shuffle the data and carve off twenty percent, is taught so early that most people never question it again. It is also, in a large fraction of real applications, quietly wrong. The implicit assumption behind a random shuffle is that every row is independent and exchangeable with every other row, and that the future will look statistically identical to the past. Both assumptions are frequently false, and when they fail, your held-out accuracy becomes a measurement of how well the model memorised the dataset rather than how well it will perform once it is live.

Here is a concrete scenario to make this less abstract. Suppose I am building a model to predict whether a customer support ticket will be escalated to a senior agent, using three years of historical tickets. Each ticket has a customer ID, a timestamp, a product category, and some text. If I shuffle all tickets randomly and take twenty percent as my test set, I will almost certainly end up with some customers who appear in both the training set and the test set, sometimes with near-duplicate tickets filed a week apart about the same recurring issue. The model does not need to generalise to solve those test rows; it just needs to recognise a pattern it has already seen under a different row index.

In deployment, the model will only ever see tickets that arrive after it is trained, from a mixture of customers it has seen before and customers it has never seen at all. A random split represents neither of those conditions faithfully. It gives you a number, and the number will look better than reality, sometimes dramatically so. The gap between reported test accuracy and real-world performance is one of the most common and most avoidable sources of embarrassment in applied machine learning.

Building the split deliberately, step by step

The fix is not a single trick but a short checklist applied in order. First, identify the unit of independence in your data. For the ticket example, it is plausibly the customer, not the ticket, because tickets from the same customer share vocabulary, product usage, and underlying issues. Second, identify whether time matters. It almost always does in anything resembling a production system, because the world drifts: new products launch, policies change, slang evolves. Third, decide what proportion of deployment traffic will come from genuinely new entities versus returning ones, because your test set should reflect that mixture rather than one extreme.

Applying this to the ticket model, I would sort all tickets by timestamp and reserve the final three months as a candidate test window, since this respects the fact that deployment only ever predicts forward in time. Within that three-month window, I would then check which customers also appear earlier in the training period. If, say, seventy percent of deployment traffic in practice comes from existing customers and thirty percent from new sign-ups, I want my test set to roughly mirror that seventy-thirty split rather than being accidentally all-new or all-returning, because either extreme would bias the reported metric away from reality.

A concrete numeric illustration helps here. Imagine the naive random split gives ninety-one percent accuracy on escalation prediction. After rebuilding the split by time and by customer, with the held-out period genuinely following the training period and the customer mixture matched to real traffic, accuracy might land at eighty-four percent. That seven-point drop is not the model getting worse; it is the measurement becoming honest. The eighty-four percent is a far more trustworthy estimate of what a dashboard will show three months after launch, and it is the number I would actually want to defend to a stakeholder.

This also changes model selection, not just the final reported score. A model that looked best under the random split, perhaps because it slightly overfit to customer-specific quirks, can fall behind a more conservative model once the leakage is removed. Choosing architectures or hyperparameters against a leaky test set optimises for the wrong target, and you only discover this after deployment, which is the most expensive place to discover it.

customer support call centre office

Extending the idea beyond one example

The ticket scenario generalises further than it first appears. In medical imaging, the unit of independence is usually the patient, not the individual scan, because multiple scans from one patient share anatomy and acquisition artefacts; splitting by scan rather than patient is a classic and well-documented source of inflated results. In fraud detection, time ordering matters enormously because fraud tactics evolve in direct response to whatever detection method is currently deployed, so a test set drawn from the same period as training will underestimate how quickly performance decays. In recommendation systems, the relevant independence unit might be the user session, since actions within a session are correlated in ways that actions across sessions are not.

A useful habit is to write down, before touching any model code, a one-paragraph description of the exact deployment scenario: who will see predictions, on what kind of input, arriving in what order, with what known versus unknown entities. Then design the split to match that paragraph as closely as the data allows. This sounds slow, but it takes perhaps twenty minutes and saves weeks of confused debugging later when a model that scored well offline quietly underperforms in production and nobody can explain why.

It is also worth stress-testing the split itself. A simple sanity check is to look for exact or near-exact duplicate rows across the train and test partitions; another is to check whether a trivial model, such as one that predicts the most common label per customer, achieves suspiciously high test performance, which would suggest the split is still leaking identity information. Neither check takes long, and both have caught genuine problems for me in the past.

Practical takeaway

A held-out test set is only useful to the extent that it resembles the conditions the model will actually face. Before splitting any dataset, decide what the unit of independence is, whether time ordering matters, and what mixture of familiar versus novel entities deployment will present, then build the split around those three decisions rather than around convenience. The resulting number might be lower than the one a random shuffle would have given you, but it will be the number that still holds up after the model ships, which is the only number that was ever worth reporting.

data analyst reviewing charts on laptop
← All writing See the project case studies →