Data drift & concept drift

In one sentence

Data drift is when inputs change, P(X); concept drift is when the input-to-outcome relationship changes, P(Y|X). Detect the first with PSI or KS on features, the second mainly by tracking outcomes.

Analogy: A spam filter starts seeing new senders and topics (data drift). Then scammers copy the exact tone of real banks, so emails that used to look safe are now scams (concept drift).

Input drift is the cheap, early alarm; delayed outcomes decide whether it matters and are the only way to see concept drift.

How it works

  • Label drift is a third kind: P(Y) changes, like the fraud rate doubling.
  • Compare each feature with a reference, usually training data; PSI < 0.1 is stable, > 0.25 significant.
  • At large n every KS p-value is tiny, so threshold the statistic, not the p-value.
  • Input drift is a cheap early warning, not proof of harm; outcomes arrive late, so watch predictions meanwhile.
  • Retrain on a schedule, on sustained drift in key features, or on a measured metric drop.

Check yourself

Answer to mark it learned; your answers aren't scored.

A credit model has tracked weekly PSI on every input for a year: all features stay below 0.05. Meanwhile 60-day default rates rose from 2.1% to 3.4% as interest rates climbed. What's the best explanation?

Go deeper

Full explanation

Models assume the future looks like the training data. Drift is when it doesn't.

  • Data drift (covariate shift): P(X) changes: a new user mix, market or sensor calibration. The learned rule may still hold.
  • Concept drift: P(Y|X) changes. Same inputs, different right answer: fraudsters adapt, demand shifts (COVID in 2020).
  • Label drift (prior shift): P(Y) changes: the fraud rate doubles.

Detecting it: compare live data with a reference (usually training data), per feature.

  • PSI bins the reference (often deciles) and sums (a−e)·ln(a/e). Rule of thumb: <0.1 stable, 0.1–0.25 moderate, >0.25 significant.
  • KS test: the max gap between two CDFs; at large n every p-value is tiny, so threshold the statistic.
  • KL / JS divergence: JS is symmetric and bounded, easier to alert on.
  • Text: compare embedding centroids, or train a reference-vs-live classifier; AUC near 0.5 means no drift.

Input drift is a cheap early warning, not proof of harm. Concept drift only shows in outcomes, which arrive late, so watch the prediction distribution meanwhile (Monitoring models in production). Retrain on schedule, on sustained drift in key features, or on a measured metric drop.

LLMs: queries drift in topic and bring product names your index has never seen; cluster them weekly and track the share outside known clusters.

Code Population Stability Index (PSI) with reference deciles
pythonPopulation Stability Index (PSI) with reference deciles
import numpy as np

def psi(expected: np.ndarray, actual: np.ndarray, bins: int = 10) -> float:
    # Bin edges come from the REFERENCE (deciles) and are applied to both
    edges = np.quantile(expected, np.linspace(0, 1, bins + 1))
    edges[0], edges[-1] = -np.inf, np.inf
    e = np.histogram(expected, edges)[0] / len(expected)
    a = np.histogram(actual, edges)[0] / len(actual)
    e, a = np.clip(e, 1e-6, None), np.clip(a, 1e-6, None)  # empty bins: avoid log(0)
    return float(np.sum((a - e) * np.log(a / e)))

rng = np.random.default_rng(0)
train_income = rng.lognormal(10.0, 0.5, 50_000)
live_income = rng.lognormal(10.2, 0.5, 5_000)  # median up ~22%

score = psi(train_income, live_income)  # ~0.15 (0.147 with this seed)
status = "stable" if score < 0.1 else "moderate" if score < 0.25 else "significant"
print(f"PSI={score:.3f} -> {status}")
Real example

A credit-limit model trained on 2023 applications monitors income and requested_amount. After a partner channel launches, weekly PSI on requested_amount jumps to 0.31 while income stays at 0.04: data drift from a new applicant mix. Approval rates move, but 60-day default rates, available two months later, hold steady, so the team adds the channel as a feature and retrains on schedule. A year later PSI is flat, yet defaults rise from 2.1% to 3.4% as interest rates climb: concept drift, invisible to every input monitor and caught only because outcomes were tracked.

Trade-offs +3 · −3

+ You gain

  • Input drift is visible immediately, weeks before labels arrive.
  • Cheap: PSI and KS per feature run in a SQL job or a few lines of numpy.
  • Turns retraining from a calendar habit into a decision backed by evidence.

− You pay

  • Noisy: with hundreds of features something always drifts, and most of it doesn't hurt the model.
  • Blind to pure concept drift: inputs can look identical while the right answers change.
  • Thresholds like PSI 0.25 are conventions, not guarantees; they depend on binning and sample size.

Use it when

Every production model from day one: monitor the top features by importance, the prediction distribution and, when labels arrive, the real metric.

Avoid it when

Don't retrain on every drift alert; confirm impact on outcomes or important features first. And don't run raw p-value tests on millions of rows: everything comes out significant.

Numbers to know 5
  • PSI rule of thumb: <0.1 stable, 0.1–0.25 moderate shift, >0.25 significant shift worth acting on.
  • PSI is usually computed on 10 reference bins (deciles); empty bins need a small floor to avoid log(0).
  • Two-sample KS at n = m = 100k: D above ~0.006 is already significant at p < 0.05.
  • JS divergence is bounded in [0, 1] with log base 2; KL is asymmetric and infinite on empty bins.
  • Domain-classifier check: AUC ≈ 0.5 means reference and live data are indistinguishable.
Common pitfalls 4
  • Taking PSI bins from the live data or changing them between runs, so the score tracks the binning, not the data.
  • Alerting on every feature equally instead of weighting by feature importance.
  • Treating stable inputs as a healthy model: concept drift doesn't show in P(X).
  • Using last week as the reference, so slow drift creeps in and the baseline drifts with it.
Interview questions 3

Answer out loud first, then reveal.

Data drift vs concept drift: what's the difference and how do you detect each?Show answer

Data drift is P(X) changing: the inputs look different, like a new customer segment. Concept drift is P(Y|X) changing: same inputs, different correct answer, like fraudsters adapting. I detect data drift directly on features, with PSI or KS per important feature against the training reference, plus the prediction distribution. Concept drift I can only confirm with outcomes, which are delayed, so I track the real metric as labels arrive and use proxies like score distributions and manual override rates meanwhile. Input drift is my early warning; outcomes decide whether I retrain.

PSI on a feature jumped to 0.3. What do you do?Show answer

First I check it's real: a pipeline bug, a unit change or a spike in missing values explains a lot of 'drift'. Then I check impact: how important is the feature, did the prediction distribution move, and do the labels we have show a metric drop? If it's a pipeline bug, I fix the pipeline, not the model. If it's a genuine population shift with measurable harm, I retrain on recent data, sometimes upweighting the new segment, and validate per slice. If the metric holds, I log it, possibly refresh the reference, and keep watching.

How do you detect drift in an LLM app with free-text inputs?Show answer

There are no tabular features, so I monitor in embedding space and in behavior. Weekly, I embed a sample of queries, cluster them and track the share far from known clusters; that's how new product names and intents show up. A classifier that separates last month's queries from this week's gives one drift score: AUC near 0.5 means no drift. I pair it with behavioral signals: falling retrieval scores, more 'I don't know' answers, more thumbs-down. New clusters become eval cases and, often, new documents in the index.