Data leakage is when information that will not be available at prediction time is present during training. The model learns from it, the validation set contains the same contamination, and the reported score is excellent. Production is the first environment where the information is genuinely absent, which is why leakage is usually discovered after deployment rather than before. It comes in four distinct forms — target leakage, train-test contamination, temporal leakage and group leakage — and each has a different fix.

An unexpectedly high score is evidence to investigate, not evidence to celebrate. Leakage is the most common explanation and the cheapest to rule out early.

Updated 23 Aug 2026 · Data and Data Quality hub

Industrial pump and rotating equipment monitored by condition sensors
Maintenance records are written after a failure, which is what makes them leak into a predictive model. Contextual photo.

What problem does this solve?

A utility builds a pump-failure model on two years of sensor history. Cross-validated ROC-AUC comes out at 0.98. The team ships it. Over the following quarter it predicts almost nothing useful, and the failures it does flag are ones the maintenance planners had already scheduled.

Two things went wrong. The rows were shuffled randomly before splitting, so readings from ten minutes after a failure sat in the training set while readings from ten minutes before sat in the test set — the model was effectively interpolating within a single event it had already seen.

Second, one feature was `work_order_raised`, populated by the maintenance system. It is present in the historical table and it is a consequence of the failure, not a predictor of it. At prediction time it is always empty. The model had learned to read the answer.

How the solution works

Ask one question of every feature: would this value exist, with this value, at the moment the prediction has to be made? If the answer is no, or if it is populated by a process that happens after the event, it leaks.

Split by time for anything with a temporal ordering. Training on the past and testing on the future is the only split that reflects how the model will be used.

Split by group where records share an entity. All readings from one pump, all images of one patient, all transactions from one account must fall entirely on one side of the split.

Fit every transformation inside the fold. Scalers, imputers, encoders and resamplers must learn their parameters from training data only, or statistics from the test set flow backwards into training.

  1. 1
    Information enters the feature set A column derived from the outcome, or computed using the whole dataset, is included among the inputs.
  2. 2
    The model finds it Optimisation exploits the strongest available signal, and a leaked feature is by construction the strongest.
  3. 3
    Validation confirms it The validation split carries the same contamination, so the score rises rather than falling.
  4. 4
    Nobody questions the number A high score is reported as success. This is the point at which leakage should have been suspected.
  5. 5
    Production removes it At inference the leaked field is empty or the future is genuinely unknown, and performance collapses to the model's real ability.

Reference architecture

Leakage enters at four points. Each is prevented by a different discipline, and a pipeline that guards only one of them is not protected.

LayerWhat it contains
Feature definitionTarget leakage: a column that is a consequence of the outcome, or is populated after it.
Split constructionTemporal and group leakage: shuffling time-ordered data, or letting one entity appear on both sides.
Transformation fittingPreprocessing leakage: scalers, imputers and encoders fitted on the full dataset before splitting.
Selection and tuningEvaluation leakage: feature selection or hyperparameter search performed on data that later serves as the test set.

Deployment options: The strongest structural defence is a feature store with explicit point-in-time semantics, so a feature's value is always retrieved as of the prediction timestamp rather than as of today.

Key capabilities

Feature availability audit

Every feature classified by whether it exists, and with what value, at prediction time.

available

Split strategy review

Temporal and group constraints applied to the split so the score reflects deployment conditions.

available

Pipeline refactoring

All transformations moved inside the fold so no statistic crosses the split boundary.

custom development

Point-in-time feature retrieval

Feature values served as of the prediction timestamp, closing the most persistent source of temporal leakage.

custom development

Integrations

Leakage is prevented in the data platform more than in the model code, because the guarantees have to hold across every retrain.

SystemIntegration point & data exchangedDirection
Feature storePoint-in-time correctness enforced so a lookup cannot return a value recorded after the prediction moment.bi-directional
Training pipelinePreprocessing, resampling and selection all executed inside the fold. → SMOTE: Inventing Minority Examples Without Copying Thembi-directional
Model registrySplit strategy recorded with the model so a later reviewer can see how the score was produced.bi-directional

Industry use cases

Predictive maintenance

Work orders, repair codes and downtime flags are all consequences of failure and all leak.

Credit decisioning

Collections status and account closure reason are populated after default and must be excluded.

Logistics delay prediction

Actual arrival time and exception codes are recorded after the delay they are meant to predict.

Customer churn

Final invoice flags and cancellation reasons are recorded at churn, not before it.

UAE & GCC considerations

Where an entity has consolidated data into a single warehouse for reporting, leakage risk rises rather than falls: reporting tables are typically built as-of-today, with dimensions overwritten in place, so a historical lookup returns the current value rather than the value at the time. Before training on a warehouse table, confirm whether it carries slowly-changing-dimension history or has been flattened. Building a point-in-time view is often the largest single piece of work in a UAE or GCC predictive-maintenance programme, and it belongs in the plan rather than in the surprises.

Implementation approach

  1. 1
    List and interrogate features For each, establish whether it exists at prediction time and what process populates it.
  2. 2
    Choose the split deliberately Time-based for temporal problems, grouped for repeated entities, both where both apply.
  3. 3
    Move everything into the pipeline No fitting of any transformation outside a fold, including scaling, imputation and resampling.
  4. 4
    Screen for suspicious features Score each feature alone; anything near-perfect on its own is a leakage candidate.
  5. 5
    Re-baseline the expectation Report the honest score to stakeholders before the previous number becomes the target.

Security & deployment

Removing a leaked feature can change which data the model needs, and occasionally reduces the sensitivity of the training set — a useful side effect worth recording. Keep the feature availability audit as a governance artefact: when a regulator or an internal auditor asks why a model performs differently in production than in validation, that document is the answer.

A worked example

The same pump dataset evaluated three ways, showing how much of the score was leakage.

  1. Random split, all features. ROC-AUC 0.98. Rows from the same failure event appear on both sides, and `work_order_raised` is included.
  2. Random split, leaked column removed. ROC-AUC 0.91. Removing the target-derived feature costs seven points.
  3. Time-based split, leaked column removed. ROC-AUC 0.74. Training on the first eighteen months and testing on the last six removes the temporal advantage.
  4. Time-based split, grouped by pump. ROC-AUC 0.71. No pump appears in both training and test.

The honest figure is 0.71, not 0.98. Twenty-seven points of apparent performance were leakage. A model at 0.71 may still be commercially worthwhile — but only the 0.71 version would have survived deployment, and only that number should have gone to the steering committee.

In code

Two habits prevent most leakage: put every transformation inside a Pipeline, and use a splitter that respects time and groups.

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import TimeSeriesSplit, GroupKFold, cross_val_score

# WRONG - the scaler sees the whole dataset, including the test fold.
# X_scaled = StandardScaler().fit_transform(X)
# scores = cross_val_score(model, X_scaled, y, cv=5)

# RIGHT - every transformation is refitted inside each training fold.
pipe = Pipeline([
    ("impute", SimpleImputer(strategy="median")),
    ("scale", StandardScaler()),
    ("clf", GradientBoostingClassifier(random_state=0)),
])

# Temporal data: never shuffle. Train on the past, test on the future.
ts = TimeSeriesSplit(n_splits=5)
print("time-aware:", cross_val_score(pipe, X, y, cv=ts, scoring="roc_auc").mean().round(3))

# Repeated entities: keep every pump entirely on one side of the split.
gk = GroupKFold(n_splits=5)
print("grouped:", cross_val_score(pipe, X, y, cv=gk, groups=pump_id, scoring="roc_auc").mean().round(3))

# Cheap leakage screen: a single feature that alone predicts almost perfectly.
from sklearn.tree import DecisionTreeClassifier
for col in X.columns:
    auc = cross_val_score(DecisionTreeClassifier(max_depth=1),
                          X[[col]], y, cv=ts, scoring="roc_auc").mean()
    if auc > 0.90:
        print(f"SUSPECT: {col} alone reaches AUC {auc:.3f}")

Two honest cross-validation scores and a list of individually suspicious columns. Any single feature that reaches AUC above about 0.90 on its own is almost always derived from the target rather than predictive of it.

Diagnostic checks

  • Score each feature individually. A single column reaching AUC above 0.90 alone is almost always derived from the target.
  • Compare random-split against time-based-split performance. A large gap is temporal leakage.
  • Check whether any entity identifier appears in both training and test sets.
  • Confirm every scaler, imputer and encoder is fitted inside the fold rather than on the full dataset.
  • Ask when each feature is physically written. Anything populated by a downstream process after the event leaks by definition.
  • Verify that feature selection and hyperparameter search did not see the final test set.

When to use it

  • This investigation is warranted whenever validation performance materially exceeds what domain experts consider achievable.
  • Data is temporally ordered, which makes random splitting wrong by default.
  • Records repeat per entity — machine, patient, customer, account.
  • Features are sourced from an operational system that also records outcomes.

When not to use it

  • Performance is poor, which points to features, labels or capacity rather than leakage.
  • Each row is a genuinely independent observation with no temporal ordering and no repeated entity.
  • The pipeline already enforces point-in-time retrieval and grouped temporal splits, and the audit has been done recently.
  • The task has no target-derived fields available at all, such as a purely sensor-driven classification with externally assigned labels.

Limitations & prerequisites

  • Not all leakage is detectable statistically; some requires domain knowledge of how a field is populated.
  • Time-based splitting reduces the effective training set and usually lowers the reported score, which can be politically difficult after a high number has circulated.
  • Grouped splitting can leave too few groups for a stable estimate on small datasets.
  • Point-in-time correctness is expensive to retrofit onto a warehouse that was not designed for it.

The four leakage types

They present identically as an inflated score. The diagnostic and the fix differ.

TypeCauseFix
Target leakageFeature derived from or populated after the outcomeRemove the feature; audit availability
Train-test contaminationTransformations fitted before splittingFit everything inside the fold
Temporal leakageRandom split on time-ordered dataSplit by time; point-in-time retrieval
Group leakageOne entity present on both sidesGroupKFold on the entity identifier

A pipeline can be guarded against one type and wide open to another; check all four rather than assuming a Pipeline object covers it.

Key takeaways

  • Leakage means training on information that will not exist at prediction time.
  • It inflates the validation score because the validation set carries the same contamination.
  • There are four distinct types and a Pipeline object only guards against one of them.
  • Split by time when data is ordered and by group when entities repeat.
  • An unexpectedly high score is a reason to investigate, not to ship.

FAQ

The first signal is a score materially better than domain experts believe possible. Then score each feature alone, and compare random-split against time-based-split results.

It prevents preprocessing leakage, which is one of four types. It does nothing about a target-derived feature, a random split on time-ordered data, or an entity appearing on both sides.

No. The scaler learns the mean and variance of the test data, which flows backwards into training. Fit it inside the fold.

It lets the model train on the future and test on the past, which is not how it will be used. Time-based splitting is the only honest evaluation.

Records sharing an entity — the same pump, patient or account — split across training and test. The model recognises the entity rather than learning the pattern.

Investigate it first. If it is populated after the outcome or is a consequence of it, remove it. If it is genuinely available at prediction time and legitimately predictive, keep it.

Then the honest conclusion is that the problem is harder than it appeared. That is a valid and valuable finding, and it is far cheaper to reach before deployment than after.

Is that validation score real?

Send the feature list, the split strategy and how the labels are generated. We will trace which features are genuinely available at prediction time and rebuild the evaluation so the number can be trusted.

Request an MLOps and governance review

+971 56 404 6555 · info@swedishtechnology.com

Sources & evidence

  1. scikit-learn: common pitfalls and recommended practices — Official guidance on preprocessing leakage and correct pipeline construction.
  2. scikit-learn: cross-validation splitters — Reference for TimeSeriesSplit, GroupKFold and related strategies.
  3. Kaufman et al., Leakage in Data Mining — Formulation and taxonomy of leakage in predictive modelling.
  4. NIST AI Risk Management Framework — Governance context for measurement validity before deployment.

Vendor and product names are trademarks of their respective owners; references are for technical context and do not imply partnership, certification or endorsement unless stated on the vendor's official pages.