Why a 0.94 AUC model goes near-random in production
· 7 minute read · Pivot-al
A churn model scores 0.94 AUC on its holdout set. The team ships it. A month later the customer success lead reports that the accounts it flags are no more likely to leave than the ones it does not flag. Nobody changed the code. The model had never been good, and the evaluation that said it was had been wrong from the start.
This is one of the most common findings when we review a stalled ML project. In one representative, anonymized teardown of a Series-B B2B SaaS company, the churn prototype scored 0.94 AUC offline and near-random in production. The cause was temporal leakage: the training features contained information that did not exist at the moment the prediction would have been made.
What temporal leakage is
Every prediction happens at a moment, which we will call the prediction time. At that moment the model can only know what has already happened and has already been recorded. A training row is honest if every feature in it could have been computed at its prediction time, from data the system held at that time.
Temporal leakage is any violation of that rule: the feature value in the training row reflects events after the prediction time, and often it reflects the outcome itself.
In production the leak disappears, because the future has not happened yet. The model looks for the signal it learned to rely on and finds a constant or a null. What remains is whatever weak real signal it picked up alongside the leak. That is usually not much, because the training process had no reason to work for a subtle pattern when an obvious one was available.
How a warehouse reads the future
Most leakage comes from the default behavior of a warehouse that stores current state, and nobody has to be careless for it to happen.
- Overwritten columns.
accounts.status,plan,seat_count,owner_id,health_score. These hold today's value. Join them to a label from eight months ago and you attach today's state to an old prediction. A churned customer's seat count is zero, its plan isfree, and its owner is the offboarding queue. - Fields written by the outcome.
cancellation_reason,closed_at,exit_survey_score,final_invoice_status. They are filled in only when the outcome happens, or after it. - Aggregates with no upper bound.
total_tickets,lifetime_logins, ordays_since_last_logincomputed as of today. For a customer who left in March, days since last login computed in November is very large. The model learns that months of inactivity mean churn, which is true and no help in predicting it. - Late-arriving and backfilled data. An event that happened on the 3rd but landed in the warehouse on the 9th was not available to a prediction made on the 5th. A backfill that restated last quarter's usage makes history look cleaner than it was on the day you would have scored it.
- Derived scores. A health score maintained by an account manager, or the output of an earlier model, often already includes the knowledge that the customer gave notice.
- Preprocessing fitted on everything. Target encoding, imputation, or scaling fitted on the full dataset before the split carries information from the test period into training. The effect is usually smaller, but it belongs to the same family.
Why the holdout set did not catch it
A random train/test split draws both sets from the same table, built the same way, with the same leak. The leaked feature predicts the label in the test set exactly as well as it does in the training set. Cross-validation does not help either, because every fold shares the flaw.
A holdout set measures whether the model generalizes to more rows from the same table. It does not measure whether those rows resemble what production will see, and with leakage they do not.
How to detect it
There are four checks, and none needs more than the training table, access to the source schemas, and an afternoon.
Single-feature AUC that is too good
Compute the AUC of each feature on its own against the label. In most business problems an honest individual feature is weakly predictive, and the model earns its score by combining many of them. A single column that reaches 0.9 alone is either the label in disguise or a consequence of it.
import pandas as pd
from sklearn.metrics import roc_auc_score
def single_feature_auc(df, label, features, min_rows=200):
out = []
for f in features:
x = pd.to_numeric(df[f], errors="coerce")
m = x.notna()
if m.sum() < min_rows or df.loc[m, label].nunique() < 2:
continue
auc = roc_auc_score(df.loc[m, label], x[m])
# direction does not matter, separation does
out.append((f, round(max(auc, 1 - auc), 3)))
return sorted(out, key=lambda r: -r[1])
There is no universal threshold. Sort the list, look at anything far ahead of the rest, and trace where that column comes from and when it is written. Feature importance from the trained model gives a similar hint: one feature carrying most of the gain deserves the same scrutiny.
Features populated only after the outcome
For each suspect feature, find the write path. Ask when in the lifecycle of the entity the value is set or changed. If the source table has an updated_at column, compare it with the outcome date. Columns that are mostly updated at or after the outcome are leaking.
If the source table has no update timestamp and no history, assume the column is current state. Treat it as unsafe until someone shows otherwise.
Null patterns that track the label
Missingness is a feature whether you intended it or not. Tree models split on it directly. If cancellation_reason is null for nearly every retained customer and populated for nearly every churned one, the model does not need to read the reason, because the presence of a value is enough.
for f in features:
is_null = df[f].isna().astype(int)
if is_null.nunique() == 2:
auc = roc_auc_score(df[label], is_null)
print(f, round(max(auc, 1 - auc), 3), round(is_null.mean(), 3))
Watch for the reverse pattern as well: a column that is populated only for active customers because a cleanup job nulls it on cancellation.
Random and time-based splits disagree
Train the same model twice: once with a random split, and once by training on an earlier period and testing on a later one. Some drop in the second number is normal, because the world drifts. A large drop means the model depends on something that does not carry forward in time.
This check catches some leaks and misses others. It tends to expose leaks whose strength depends on the age of the row, since recent rows have had less of the future written into them, and leaks through the same entity appearing on both sides of a random split. But if every feature is computed from current state, the later period is leaky too, so passing this check does not mean the table is clean.
How to fix it
Give every row a prediction time
The training table needs an explicit column for the moment each prediction would have been made. Without it there is nothing to be "as of". This usually forces the label question as well: which outcome, within which window after the prediction time. That is covered in your label is a product decision nobody made.
Join point-in-time, not to current state
Every feature must be computed from data with an event time strictly before the prediction time. For state that changes, such as plan or seat count, that means keeping history instead of overwriting it. For aggregates, it means bounding the window on both sides. The mechanics, with SQL, are in point-in-time correct features.
Separate event time from ingestion time
Event time is when something happened, and ingestion time is when your system learned about it. Leakage prevention needs both, because a feature is available at prediction time only if the event had happened and the record had arrived. If your pipeline loads usage data with a two-day delay, a training feature built from "usage up to yesterday" describes a model you cannot serve.
Backtest strictly forward in time
- Choose a cutoff. Train only on rows whose prediction time, and whose full label window, fall before it.
- Test on rows with prediction times after the cutoff.
- Fit every preprocessing step, including encoders and imputers, on the training fold only.
- Repeat with several cutoffs rolling forward, and report the metric for each fold as well as the average.
Then run the model in shadow mode before anyone acts on it. Score live, log each prediction with its timestamp and the feature values used, and compare once outcomes arrive. Logged features are leak-free by construction, which also makes them the most reliable training data you will have.
What to expect after the fix
The AUC will drop, and the lower number is the real one and the one to plan around. Sometimes the honest model is still useful. In other cases the fix shows that the data does not carry enough signal for the use case yet, and that is a finding about the data, with the modeling not at fault. Learning that from a backtest costs far less than learning it from a failed launch. Leakage is one of eight dimensions we look at in data readiness for machine learning.
Check your own data
You can run a first pass yourself with the leakage check: drop a CSV sample of a training table into the browser and it flags suspected leakage, label, and drift problems. The data never leaves your browser. If you want a senior engineer to look at the results with you, the teardown clinic is a free 30-minute live session. For a full assessment of the data and the model, see the Data & Model Feasibility Teardown.
