Skip to content

July 12, 2026 • Ibexcode

Building a Temporal ML Ranking System Without Data Leakage

Diagram of a leakage-free temporal ML ranking pipeline, from DataOps to final ranking

With temporal data, a good metric isn’t enough to show that a Machine Learning model works. We also need to understand how the data was prepared and, more importantly, what the model could actually have known at the time of each prediction.

The problem gets harder when multiple candidates belong to the same event and must be ranked against one another. It becomes more delicate still when one model’s predictions are used to train the next, as in a stacking architecture.

That’s the problem explored here: ranking candidates from their history, then combining several models’ predictions in a multi-level system.

Its validation rests on one central invariant:

Every historical prediction must be computed using only information that would genuinely have been available when that prediction was made.

For an isolated model, this is relatively straightforward to check. Once historical features, several stacking levels, learned preprocessing, and calibration enter the picture, however, the rule has to hold across the entire pipeline—not just the final model.


1. A Temporal Ranking Problem

The dataset consists of events, each containing several candidates.

Relative ranking of multiple candidates within the same event

The system isn’t simply estimating an independent value for every observation. It must also capture the relationships among candidates within each event.

The architecture can combine different learning objectives or representations. Some models produce continuous signals for individual candidates, while others model the event’s relative structure more directly.

Different approaches may achieve similar overall performance while capturing partly distinct signals or making different errors. Subsequent levels can potentially exploit that complementarity.

Conceptually, one level can be represented as follows:

Architecture combining complementary models

What matters here isn’t the precise family of models, but how information moves between levels. When one level’s predictions become the next level’s training inputs, temporal causality must be guaranteed not only in the original dataset but at every boundary in the stack.


2. Temporal Causality in the Validation Protocol

In this setting, randomly splitting the data isn’t an option: a model could end up training on events that happened after those it is supposed to predict.

How a random split can cause temporal leakage

Independence between training and test sets isn’t sufficient when time matters. A prediction for time t must come from a pipeline whose entire learned state was built exclusively from information available before t.

That includes the model, historical aggregations, learned transformations, and every other data-derived artifact. The fundamental constraint can be written as:

max(train_date) < min(evaluation_date)

The main protocol therefore preserves a strict chronological split:

TRAIN → CALIBRATION → TEST

The test period comes after all data used to build the system. This is sufficient to evaluate a model trained directly on the training set.

It is no longer sufficient when that model’s predictions are used to train another model.


3. Stacking Creates a New Leakage Boundary

Consider a meta-model combining the predictions of two models, A and B. It would be incorrect to train A and B on the entire dataset, ask them to predict that same dataset, and use those predictions to train the meta-model.

Even if the meta-model never directly receives the targets used by A and B, its inputs were generated by models that had already seen those targets. Its training features are therefore in-sample.

In production, the distribution will differ because the first-level models must predict genuinely unseen observations. Preventing leakage in stacking isn’t simply a matter of hiding the target from L2. We must also ensure that the L1 outputs consumed by L2 were themselves generated out of sample.

How a prediction passes to the next stacking level


4. Building Temporal Out-of-Fold Predictions

Features for the next level are built from Out-of-Fold (OOF) predictions. In a temporal setting, however, the usual OOF requirement isn’t enough. An observation can be excluded from the training fold while still being predicted by a model trained on future data.

Both conditions must hold:

observation ∉ train

and:

max(train_date) < observation_date

We generate OOF predictions using expanding training windows.

Future-only Out-of-Fold prediction protocol

Each window adds more available history without crossing the temporal boundary of the period it predicts.

After concatenating the results, every score in the resulting dataset corresponds to a genuine historical out-of-sample prediction:

date       features       prediction_L1
─────────────────────────────────────────
t₁            ...              0.42
t₂            ...              0.71
t₃            ...              0.33
t₄            ...              0.64

Those predictions can now become features for the next level without directly carrying in-sample training results into it.


5. The Event Is the Atomic Unit of Validation

Chronological splitting doesn’t solve everything. We must also pay attention to how events are assigned to folds.

In ranking, observations within an event aren’t independent: each candidate’s position only makes sense relative to the other candidates in the group. An event must therefore never be split across folds.

For example:

Event 42
├── A
├── B
├── C
├── D
└── E

All five candidates must belong to the same partition.

The atomic validation unit is therefore the entire event, not an individual dataset row. This must hold for OOF folds, model comparisons, and subsequent statistical procedures. It also prevents a subtler form of contamination: allowing a model to learn part of an event’s context before asking it to rank the remaining candidates.


6. Causal Feature Engineering

Even a flawless chronological split can’t protect us from leakage introduced earlier, during feature engineering. Historical features must obey exactly the same temporal constraint.

For any feature computed at time t:

feature(t) = f(observations before t)

This applies to cumulative statistics, historical averages, frequencies, success rates, rolling windows, category aggregations, historical rankings, and target-dependent transformations.

An aggregation computed once over the entire dataset before splitting can contaminate every historical observation—even if the models themselves are trained with perfectly chronological folds.

The temporal boundary must therefore be enforced when constructing the data, not merely when training the models.


7. Isolate Learned Transformations

It’s natural to isolate the data used by a model. But some preparation steps also learn parameters from historical observations.

Normalization, for example, may use the observed mean and standard deviation:

x' = (x - μ) / σ

where:

  • x is the original value;
  • x' is the normalized value;
  • μ is the mean of the observed values;
  • σ is their standard deviation, measuring their spread around the mean.

If μ and σ are computed from the full dataset, they indirectly incorporate future information. Historical observations are then transformed using statistics that didn’t yet exist at the time.

The same risk applies to imputing missing values from observed statistics, certain categorical encodings, target encoding, feature selection, quantile transformations, dimensionality reduction, importance-based feature selection, and calibration.

The principle goes beyond the distinction between models and preprocessing. The useful question is:

Does this step learn anything from data in order to do its job?

If it does, its inputs must also respect the timeline. A preprocessing step can introduce temporal leakage just as readily as a model when it learns from information unavailable at the simulated prediction time.


8. Recursively Enforcing the OOF Constraint

With multiple stacking levels, the same logic applies at every stage, without exception.

Consider:

L1 → L2 → L3

Temporal OOF predictions from L1 are used to build L2’s training dataset. But if we then train L2 on that entire dataset and use its in-sample predictions to train L3, we reintroduce exactly the leakage that was removed between L1 and L2.

The constraint must therefore be recursive. Every level that supplies predictions to a higher level must produce its own out-of-sample, future-free predictions.

Each boundary between stacking levels is a new validation boundary. This is a structural property of the stack, not a check to bolt on after training.


9. Stack Depth and the Erosion of Usable History

This rigor has an easily overlooked consequence: the deeper the stack, the less usable history remains for the upper levels. Compute time isn’t the only cost.

Consider several chronological segments:

A → B → C → D → E

To generate first-level OOF predictions:

A       → predict B
A+B     → predict C
A+B+C   → predict D
A+B+C+D → predict E

No genuinely future-only OOF prediction can be generated for A, because no earlier period is available.

The L2 dataset therefore starts later than the L1 dataset. If L2 must generate OOF predictions for L3, another portion of the history becomes unavailable.

Erosion of usable history across future-only OOF stacking levels

Stack depth creates a trade-off among combination capacity, usable history, window size, fold count, and the statistical stability of upper levels.

OOF splitting isn’t merely a validation setting. It directly shapes the architecture.


10. From OOF Models to Production Inference

Models trained on the different folds are initially used to generate out-of-sample predictions for training subsequent levels. That doesn’t mean they must be discarded afterward—or that they must necessarily be kept.

Several inference strategies are possible. Fold models can be retained and their predictions combined, or they can be used only to build OOF datasets before training a separate inference model on a longer history.

In the first case, a level containing several temporal folds might look like this:

Level
├── fold model 1
├── fold model 2
├── fold model 3
├── ...
└── fold model N

During OOF generation, each model obeys a strict temporal constraint: it may produce training predictions only for observations later than its own training data.

For a genuinely new observation occurring after all those historical periods, several of these models may instead be used simultaneously and their outputs aggregated.

Example of using an OOF model ensemble in production

Fold models can thus become components of the production inference pipeline, depending on the chosen strategy. This allows us to exploit models trained at different historical cutoffs rather than treating folds as temporary validation artifacts.

But it isn’t an OOF requirement. Another design may use folds exclusively for constructing out-of-sample training data, then build a separate production model.

The important distinction is:

  • OOF generation determines how to construct historical predictions without information leakage.
  • The inference strategy determines which models actually run after deployment.

These decisions are related, but they aren’t interchangeable.

Whatever the strategy, the signals used to train an upper level must remain representative of the signals it will receive during inference. A large mismatch can introduce distribution shift even when temporal causality is perfectly respected.

Preventing leakage is necessary for a valid stack; it doesn’t eliminate the need to check consistency between training and production.


11. Calibrating Models on a Dedicated Temporal Period

Calibration is often associated with the final output of a pipeline. In practice, it can happen earlier whenever a model produces a score that needs a probabilistic interpretation.

We should distinguish two roles:

  • the model, which learns a useful prediction or ranking signal;
  • the calibrator, which learns how to associate a probability with that signal.

Conceptually:

data → model → score → calibrator → probability

Not every component in a multi-level architecture needs to output probabilities. Calibration is neither mandatory at every level nor necessarily a single transformation applied at the end. It belongs wherever the role of a model’s output calls for a probabilistic interpretation.

Calibration Depends on the Model’s Role

Some model outputs can be passed directly to the next level; others may need calibration first.

Calibration can be attached to models that need it

The key isn’t how many calibrators exist or exactly where they sit, but what they do:

When necessary, transform a model’s signal into a probability with a meaningful statistical interpretation.

This also distinguishes calibration from OOF generation. OOF addresses out-of-sample validation. Calibration answers a different question: what probability can reasonably be assigned to the model’s signal?

Why Calibration Needs Its Own Period

A model score isn’t necessarily a probability. Two candidates receiving:

score A = 0.8
score B = 0.4

may be correctly ordered without those values meaning an 80% and 40% chance of the outcome, respectively.

Calibration learns the relationship between the model’s signal and observed frequencies. It needs two pieces of information:

model prediction + actual observed outcome

The calibrator must not be fitted on in-sample predictions generated by a model trained on the same observations. Models usually perform better on data they’ve already seen than on genuinely new data.

Consider a simplified example. A particular score level might correspond to:

80% success rate
on the model's training observations

but

65% success rate
on new observations

Calibration fitted on the first set could map that score to a probability near 80%, even though its observed behavior on unseen data is closer to 65%.

The calibrator learns from data too. It must be fitted using out-of-sample predictions for observations excluded from the underlying model’s training.

Several protocols can enforce this. In the protocol described here, we reserve a dedicated later time period for calibration, after the model-training period.

Temporal separation between model training and calibration

The model is first trained on its permitted history. It then predicts a later period it hasn’t seen. Those predictions, paired with the actual outcomes, are used to fit the calibrator.

This teaches the calibrator to interpret model behavior under conditions much closer to the real use case: predictions on new observations. Temporal separation protects not only the model’s training but also against artificially optimistic calibration.

Calibration Must Match the Signal Actually Used

Temporal isolation alone isn’t enough. The calibrator learns a mapping:

model signal → observed probability

The signal used to fit it must remain representative of what it will receive at inference time. If the signal-generation process changes significantly between calibration and production, the learned relationship may no longer hold.

Changing the model, its training history, the way outputs are combined, or an upstream transformation can all shift the distribution of scores presented to the calibrator.

Two separate properties must be preserved:

Calibration must be learned from out-of-sample predictions on observations excluded from the underlying model’s training.

and:

The signal used to fit the calibrator must remain representative of the signal produced at inference time.

The first guards against overly favorable calibration based on in-sample predictions. The second guards against a mismatch between the conditions under which calibration was learned and those under which it is used.

A Learned Component in Its Own Right

A calibrator should be treated as a learned system component, just like any other data-fitted transformation. It has training data, a temporal boundary, learned parameters, a relationship with its input signal, and operating conditions that must remain consistent with its training.

The number and placement of calibrators depend on model roles and output types, not mechanically on stack structure: nothing requires one calibrator per fold, or a single final calibrator for the whole stack.

The general rule is simpler:

Every calibrator must be learned from out-of-sample predictions representative of the signal it will interpret after deployment.

Calibration is another learning boundary and deserves the same validation rigor as the models it accompanies.


12. Test-Set Reuse and Selection Bias

It’s possible to avoid temporal leakage entirely and still overestimate a system’s progress. This can happen when we compare variant after variant on the same test period.

This isn’t data leakage in the strict sense: the model never accesses test data during training. The bias comes from how experiments are selected.

Imagine evaluating dozens of variants on the same sample:

Model A             → 35.8%
Model B             → 35.9%
New feature         → 36.0%
Model C             → 35.7%
New combination     → 36.1%
...

Each result influences the next decision: keep a feature, discard an architecture, change a hyperparameter, or try another combination.

As experiments accumulate, the risk grows that we select a configuration that unintentionally exploits the statistical peculiarities of that specific period, rather than a genuinely generalizable improvement.

That’s why a small test-set gain isn’t sufficient evidence on its own. It needs to be interpreted in light of how many experiments were run and checked against temporal stability, paired comparisons, bootstrap estimates, consistency across segments, and the behavior of the complete system.

The test set remains outside model training, but repeatedly consulting it calls for caution when interpreting small gains.


13. Statistical Robustness of Observed Gains

A rigorous temporal protocol makes comparisons more credible. It still doesn’t prove that a difference of a few tenths of a percentage point represents real progress rather than sample variability.

Suppose two models are evaluated on exactly the same events:

Model A: 35.7%
Model B: 36.1%

On that period, B really is ahead by 0.4 percentage points. But an important question remains:

Is B genuinely better, or did we happen to evaluate both models during a period that favored B slightly?

Some events favor A; others favor B. When the overall difference is small, a handful of favorable events may reverse the ranking. We therefore need to examine not only the average difference but also how stable it is.

Compare Models on the Same Events

Comparisons are paired: A and B are always evaluated on the same events.

The event remains the indivisible unit. We can use bootstrap resampling to simulate many alternative samples from the observed period by drawing events at random, with replacement:

Original sample:

[E1, E2, E3, E4, E5, E6, E7, ...]

Some bootstrap samples:

Bootstrap 1: [E4, E7, E7, E12, E2, ...]
Bootstrap 2: [E3, E1, E9, E9, E14, ...]
Bootstrap 3: [E8, E2, E4, E4, E11, ...]
...

Some events appear several times, while others are absent.

For each resampled dataset, both models’ performance is recalculated and compared:

Δ = performance(B) - performance(A)

After many repetitions, we have more than a single +0.4-point difference: we have a distribution of plausible differences.

Conceptually:

Bootstrap distribution showing no advantage over the baseline

What the Distribution Tells Us

If B has a robust advantage, the great majority of resampled datasets should still favor B:

Bootstrap distribution showing a robust advantage over the baseline

If the distribution crosses zero substantially:

Bootstrap distribution showing an uncertain advantage over the baseline

then modest changes to the sample frequently erase B’s advantage or even make A the better model.

The measured result:

B = 36.1%
A = 35.7%

remains perfectly accurate for that period. What bootstrap challenges isn’t the measurement itself, but how strong a conclusion we can draw from it.

A Measured Difference Isn’t Necessarily a Useful Improvement

This matters especially in mature architectures, where remaining gains tend to be small. A new model may improve the average metric without an advantage stable enough to justify additional complexity, longer training, more expensive inference, new artifacts to maintain, or replacing the current production model.

Promotion decisions therefore require more than:

metric(B) > metric(A)

They require a tougher question:

Do the data provide enough evidence to treat the observed advantage as robust?

Paired bootstrap is one tool for answering it. It complements temporal validation: temporal validation seeks to reproduce real inference conditions; bootstrap measures how much our conclusion depends on the particular sample we observed.


14. Evaluate Ranking from Several Angles

In ranking, the right evaluation depends on what the ranking is supposed to achieve. A single metric rarely tells the whole story.

Two systems can have similar overall scores while behaving very differently: one may be especially good at identifying the top candidates, while another may reproduce the full ordering more faithfully.

We therefore need to examine several complementary properties.

Quality at the Top of the Ranking

In many ranking tasks, not all positions matter equally. Reversing the top two candidates may matter far more than swapping two candidates near the bottom.

Metrics such as HitRate@K directly measure whether relevant candidates appear in the first K positions. NDCG@K also accounts for relevance and position, rewarding a relevant result more when it appears higher.

These metrics address a focused question:

Does the system place the important candidates high enough?

Consistency of the Overall Ranking

Focusing only on top positions can hide what happens farther down the list.

Rank-based metrics help assess whether the predicted ordering remains broadly consistent with the observed one. A system may be excellent at finding the winner while ordering the remaining candidates poorly. Another may reproduce the overall ranking very well without consistently identifying the top candidate.

These behaviors aren’t equivalent and are hard to summarize with a single number.

Probability Quality, When Probabilities Are Produced

When the system also outputs probabilities, calibration becomes a third evaluation dimension. A probability of 0.8 genuinely means “80%” only if, across enough comparable situations, the associated event occurs about eight times out of ten.

We can examine this using the Brier Score, calibration curves, and comparisons between predicted probabilities and observed frequencies.

This is distinct from ranking quality. A system may order candidates correctly while being overconfident in its probabilities. Conversely, well-calibrated probabilities don’t guarantee that the best candidates always appear in the correct order.

Evaluate Properties, Not a Universal Score

The goal isn’t to find one metric that captures every aspect of system quality. It’s to evaluate several properties:

Multi-criteria evaluation of a ranking system

These measures aren’t competitors; they describe different dimensions of the same result. This matters particularly when comparing similar configurations: improving one metric can conceal deterioration in another.

Comparisons should reflect the properties the system actually needs to preserve, rather than reducing all its behavior to one score.

Evaluating a ranking system is less about asking “What’s its score?” and more about identifying exactly where it is better, equivalent, or worse than another configuration.


15. Computational Cost of the Validation Protocol

This validation method has a real cost. In a temporal stack, testing one “model” often means running a whole series of training jobs, not just one.

To generate leakage-free OOF predictions, each model must be trained on successive historical windows:

One model
    │
    ├── train fold 1
    ├── train fold 2
    ├── train fold 3
    ├── ...
    └── train fold N

This must be repeated for the relevant models and, in a multi-level architecture, for each level that generates OOF predictions for the next.

The overall cost is therefore closer to:

N folds × level 1 models
+
calibrations associated with level 1 models
+
N folds × level 2 models
+
calibrations associated with level 2 models
+
N folds × level k models
+
calibrations associated with level k models

Or, more compactly:

Σₖ(OOF training runs at level k + associated calibrations at level k)

Calibration isn’t simply one extra operation at the end. It is attached to models that need it and has its own fitting procedure. In this protocol, calibration uses a dedicated temporal period.

Hyperparameter search adds still more work. When a configuration must be evaluated under realistic temporal conditions, a single experiment can require dozens of training runs before it can even be compared with the baseline.

Validation Cost Is Part of Model Cost

We could reduce the workload by using fewer folds, reusing predictions generated under different conditions, or simplifying validation steps. But such optimizations only make sense if they preserve the properties the protocol is designed to guarantee.

The trade-off isn’t merely:

more compute ↔ less compute

It’s closer to:

computational cost
        ↕
fidelity of temporal simulation
        ↕
amount of usable data

The number and size of folds simultaneously affect training time, how much history each model can use, and how many OOF predictions can be passed to later levels.

These are architectural decisions, not just knobs for speeding up experiments.

Research and Production Have Different Costs

Cost also depends on the context.

During research, testing a new hypothesis may require rebuilding a substantial part of the pipeline to measure its impact under conditions comparable with the baseline.

In production, inference artifacts have already been built and validated. Most of the protocol-construction cost is paid during training and experimentation; daily cost then depends on the chosen inference strategy and how many models actually run.

An ML system’s computational complexity isn’t measured solely by the cost of one production prediction. It also includes the cost of obtaining an evaluation reliable enough to justify deploying a new version.


16. Design Principles of the Validation Protocol

Across these stages, a few rules keep recurring. They don’t merely check results afterward; they shape the datasets, folds, and every level of the stack.

  1. Strict temporal causality. Every prediction for time t comes from a model trained exclusively on observations preceding t.

  2. Group integrity. The event is an indivisible validation unit. All its candidates belong to the same temporal partition and fold.

  3. Causal feature engineering. Every historical statistic, aggregation, or data-dependent feature uses only information that would have been available at the simulated time.

  4. Exclusively Out-of-Fold stacking. A stack level is never trained on predictions from a model that already saw the relevant observations. Its inputs come from OOF predictions that also respect temporal causality.

  5. Recursive OOF constraints between levels. Every level feeding another must produce its own out-of-sample, future-free predictions. Each stack boundary is another validation boundary.

  6. Isolation of all learned transformations. Every data-fitted operation respects a temporal boundary appropriate to its role. Training-related transformations use only authorized data. When calibration is needed, it is learned from out-of-sample predictions; here, we reserve a dedicated later period.

  7. Consistency between OOF construction and production inference. Production may retain fold models or use separately trained models. Either way, the signals seen by upper levels must remain representative of those used during their training.

  8. Account for test-reuse selection bias. Test data is excluded from model training. Repeatedly consulting test results can still favor configurations that happen to fit the peculiarities of that period. Small gains must be interpreted in light of experiment count and stability.

  9. Event-level paired comparisons. Models are compared on exactly the same events. When differences are small, their variability is estimated to distinguish stable improvements from sample-specific fluctuations.

  10. Promotion based on robust gains. A one-off metric improvement isn’t sufficient. A new configuration must retain its advantage under the full temporal protocol, remain consistent across the properties being evaluated, and offer enough benefit to justify any extra cost.

Together, these invariants have a direct consequence: the validation protocol is part of the system architecture.

Changing historical feature construction, OOF generation, temporal boundaries, calibration, or validation groups changes the experiment itself. Metrics measured before and after such changes aren’t necessarily directly comparable.


17. The Validation Protocol as an Architectural Component

When comparing two versions of a multi-level temporal system, their scores alone aren’t enough. We also need to know how those scores were produced.

Meaningful comparison requires visibility into the temporal boundaries, fold-grouping unit, historical feature construction, training scope of learned transformations, OOF generation method, propagation of OOF predictions between levels, calibration isolation, test-period usage, and uncertainty around measured differences.

This changes how we think about validation. It isn’t a step performed after model design. It’s a constraint that runs through the entire system.

The protocol determines what a historical prediction actually means and, consequently, what each metric measures.


18. Conclusion

For a standalone temporal model, the rule seems simple: learn from the past, evaluate on the future.

In a multi-level ranking system, the hard part is enforcing that rule everywhere data is transformed or reused. A correct chronological split doesn’t automatically protect historical features, predictions passed between levels, or calibrators. Every component must be built from information authorized at the time in question. Any stage that learns or transmits a signal deserves its own checks.

Predictions used to train upper levels must be out of sample and free of future information. Learned transformations need their own temporal scope. Calibrators must be fitted on out-of-sample predictions representative of inference conditions; in the protocol described here, dedicated later periods provide that separation. Finally, both individual levels and the assembled system must be evaluated under conditions consistent with their intended use.

Behind all these requirements lies the same invariant:

At every simulated point in time, the complete state of the system must be reconstructible using only information that would genuinely have been available at that moment.

The protocol requires more computation and can reduce the history available to upper levels. Calibration artifacts must be maintained, and statistical evaluation takes time. These are real design constraints.

In return, we gain a much clearer understanding of what the metrics actually measure and the conditions under which they were obtained. A slightly higher score means little if the data used to produce it indirectly contains future information. Likewise, an improvement measured during one period isn’t necessarily meaningful if it vanishes under a small change in the sample.

Validation must therefore answer two complementary questions:

Could the system have made this prediction using only the information available at that time?

and:

Is the measured improvement robust enough to count as genuine progress?

It’s the combination of temporal causality, OOF construction, out-of-sample calibration, and statistical robustness that turns a collection of metrics into an evaluation we can actually trust.

In this kind of system, validation cannot be added after the architecture is finished, it has to be designed alongside it.