A model learns from a snapshot of the world, then goes to work in a world that keeps moving. Prices rise, customers change, fraudsters adapt. When live data stops looking like the training data, a model can get steadily worse without a single error message. Drift monitoring compares what the model sees now with what it learned from. The loudest drift alarm is not always the dangerous one, and the most dangerous change can leave the inputs looking exactly the same. Here you’ll run the two standard drift checks on a shop’s orders, then watch a fraud model fail in a way no input check can see.
How models go stale#
A model doesn’t crash when the world changes. It keeps giving confident answers, they just get worse. The causes are ordinary: prices and seasons change; a marketing campaign brings in a new kind of customer; spammers and fraudsters study what gets blocked and change tactics; someone upstream starts recording prices in pence instead of pounds. In May 2020, MIT Technology Review reported that the sudden change in shopping during the pandemic had thrown off models for inventory, fraud detection and marketing, and people had to step in and correct them by hand.
Two kinds of change get names. Data drift is when the inputs change: the orders look different from the training data. Concept drift is when the link between the inputs and the right answer changes: orders that used to be safe are now fraud, or the other way round. They need different checks, as you’ll see.
Has this input changed?#
Take one input, the value of each order, and compare this week’s orders with the training data. Two checks are standard.
- The Kolmogorov–Smirnov (KS) test lines both groups up from smallest to largest and finds the biggest gap between them, for example “60% of training orders were under £50, but only 55% of this week’s”. Its p-value says how often a gap that big would appear by chance if nothing had changed.
- The population stability index (PSI) cuts the training data into ten equal-sized slices by value, then measures how far this week’s shares of each slice have moved. A common rule of thumb, from credit scoring: under 0.1 means no real change, 0.1 to 0.25 is worth a look, over 0.25 is a big shift.
Predict first
Prices across the shop rise by 2%. This week had 200,000 orders. Does the KS test say the order values have drifted?
With 200,000 orders, a 2% price rise sends the KS test’s p-value below 0.000001: drift, certainly. The PSI is 0.001: no real change. Both are right; they answer different questions. Now pick 1,000 orders: the same 2% rise gives a p-value of 0.960, and the test sees nothing. Push prices up 30% and the PSI reaches 0.12 to 0.13, worth a look, whatever the number of orders.
A significance test asks whether anything changed; with enough data, the answer is always yes. Monitoring tools deal with this by measuring the size of a shift rather than its certainty once the data is big. Evidently, a popular open-source monitoring library, uses the KS test by default for 1,000 values or fewer and switches to a distance measure above that.
Drift that matters, and drift that doesn’t#
Now a model with a job. The shop’s fraud filter is a logistic regression, a simple yes-or-no model, trained with gradient descent on 20,000 past orders, 3% of them fraud. It looks at two inputs, the order’s value and how long ago the account was opened. In the training data, fraud came from brand-new accounts placing big orders, so the model flags big orders from new accounts. Then four different weeks arrive.
Predict first
Fraudsters change tactics: they take over old, trusted accounts and place ordinary-looking orders. How much do the drift scores on the model’s two inputs move?
In a normal week the model catches 92% of fraud and blocks 7 honest orders out of 10,000. When prices rise 30%, the order-value PSI reaches 0.12, worth a look, but the model copes: it still catches 95% of fraud and blocks 12 honest orders. When the customer base matures and accounts get older, the account-age PSI hits 1.32, by far the loudest alarm of the four, and nothing is wrong at all: old accounts were always the safe ones.
Then the fraudsters change tactics. The inputs barely move (PSI 0.01 for both), and the model catches 0% of the fraud. That’s concept drift: the inputs look the same, but what they mean has changed, so no check on the inputs alone can find it. One number did move this week, though. The share of orders flagged fell from 3.1% to 0.1%, because the model stopped seeing anything suspicious. Input drift says the world looks different; only outcomes can say the model is wrong, and they arrive late.
What to monitor#
Because each check misses something, teams watch several layers:
- Data quality: missing values, new categories, numbers in the wrong units. Pipeline problems like these are a common cause of sudden breakage, and the cheapest to catch.
- Input drift: a PSI or distance per input, checked daily or weekly. Weigh it by how much the model uses each input: drift in an input that barely moves the model’s predictions (its SHAP importance, say) matters little.
- Prediction drift: the share flagged, the average score, the mix of answers. It needs no labels, so it’s available immediately. It caught the new fraud tactics here; it won’t always.
- Outcomes: accuracy on cases whose true answer has come in, from chargebacks, returns or human review. The slowest signal and the only definitive one. To speed it up, have people label a small random sample of cases each week.
In code#
Both checks on made-up order values, with NumPy and SciPy (pip install numpy scipy):
import numpy as np
from scipy.stats import ks_2samp
rng = np.random.default_rng(0)
training = 40 * np.exp(0.7 * rng.standard_normal(100_000)) # order values in £
this_week = 1.02 * 40 * np.exp(0.7 * rng.standard_normal(200_000)) # prices up 2%
def psi(before, now, bins=10):
"""Population stability index over the deciles of `before`."""
edges = np.quantile(before, np.linspace(0, 1, bins + 1)[1:-1])
p = np.bincount(np.searchsorted(edges, before, side="right"), minlength=bins) / len(before)
q = np.bincount(np.searchsorted(edges, now, side="right"), minlength=bins) / len(now)
p, q = np.clip(p, 1e-4, None), np.clip(q, 1e-4, None)
return float(np.sum((q - p) * np.log(q / p)))
test = ks_2samp(training, this_week)
print(f"KS gap {test.statistic:.4f}, p-value {test.pvalue:.1e}")
print(f"PSI {psi(training, this_week):.4f}")
# KS gap 0.0143, p-value 3.2e-12
# PSI 0.0010The same story as the figure: a tiny p-value and a tiny PSI. In production, libraries such as Evidently run checks like these across every input and build the reports and dashboards for you.
What to remember
- Models get worse silently when live data stops resembling training data (data drift) or when what the data means changes (concept drift).
- Significance tests flag tiny shifts once data is big; measure the size of a shift (PSI or a distance) and weigh it by how much the model uses that input.
- Watch inputs, predictions and outcomes: only outcomes can show concept drift, and they arrive late.