5.3.13MLOps & Deployment

Data drift and concept drift detection

2,060 words9 min readdifficulty · medium4 backlinks

WHY does drift even exist?

We can split the joint distribution using the chain rule:

P(X,Y)=P(YX)P(X)P(X, Y) = P(Y \mid X)\, P(X)

This factorization is the whole conceptual key — everything below falls out of asking which factor changed.

Figure — Data drift and concept drift detection

WHAT are we actually measuring?

You never observe PP directly — only samples. So detection = comparing a reference window (training/recent-good) against a current window (live) and asking "are these two samples from the same distribution?"

1. Data drift — compare input distributions

We compare the reference feature distribution Pref(X)P_{ref}(X) to the current Pcur(X)P_{cur}(X).

2. Concept drift — you must monitor error


Worked example: computing PSI


Common mistakes (steel-manned)


Active recall

Recall Feynman: explain it to a 12-year-old

Imagine you learned to catch a ball by watching how your friend throws. Data drift is when a different friend starts throwing — the balls come from new angles (the inputs changed), but a ball still flies the same way, so you can still catch. Concept drift is spookier: the rules of physics seem to change — the same throw now curves differently, so your old catching habit fails. Drift detectors are like a coach constantly asking "are these throws still like the ones you practiced on?" (data drift) and "are you still catching them?" (concept drift). If either answer is "no," time to practice again.


Connections


#flashcards/ai-ml

Chain rule factorization used to define drift
P(X,Y)=P(YX)P(X)P(X,Y)=P(Y\mid X)P(X); data drift changes P(X)P(X), concept drift changes P(YX)P(Y\mid X).
Data drift (covariate shift) definition
P(X)P(X) changes while P(YX)P(Y\mid X) stays fixed — inputs shift but the input→output rule is intact.
Concept drift definition
P(YX)P(Y\mid X) changes — the same input now maps to different labels; the underlying rule changed.
PSI formula
PSI=i(ciri)lnciri\text{PSI}=\sum_i (c_i - r_i)\ln\frac{c_i}{r_i} over binned proportions; symmetrized KL.
Why PSI is always ≥ 0
sign(ciri)=sign(lnciri)\text{sign}(c_i-r_i)=\text{sign}(\ln\frac{c_i}{r_i}), so every term is non-negative (equivalently it's a symmetrized KL divergence).
PSI thresholds
<0.1 no drift, 0.1–0.25 moderate, >0.25 significant.
KL divergence formula
DKL(PQ)=iPilnPiQiD_{KL}(P\|Q)=\sum_i P_i\ln\frac{P_i}{Q_i}, always ≥0 by Jensen, =0 iff P=Q.
KS statistic
D=supxFref(x)Fcur(x)D=\sup_x|F_{ref}(x)-F_{cur}(x)|, the maximum vertical gap between empirical CDFs.
Test for categorical feature drift
Chi-square: χ2=i(OiEi)2/Ei\chi^2=\sum_i (O_i-E_i)^2/E_i comparing observed vs reference-expected counts.
DDM warning/drift rule
warning at pi+sipmin+2sminp_i+s_i\ge p_{min}+2s_{min}, drift at pmin+3smin\ge p_{min}+3s_{min}, with si=pi(1pi)/nis_i=\sqrt{p_i(1-p_i)/n_i}.
Why concept drift needs labels
It's a change in P(YX)P(Y\mid X); you can only see the rule break by comparing predictions to true YY (or proxies like confidence/output ratios).
Why "bigger current window" hurts detection
A large window averages over the change point, delaying and diluting the drift signal; use adaptive/sliding windows (ADWIN).

Concept Map

breaks after deploy

split by chain rule

P of X changes

P of Y given X changes

inputs differ, rule intact

mapping broken

detect by comparing

per-bin log-ratio metric

equals symmetrized

threshold above 0.25

protects

Stationary assumption P of X,Y

Drift exists

P of X,Y = P of Y given X times P of X

Data drift / covariate shift

Concept drift

Fix: reweight / monitor

Fix: retrain with new labels

Reference vs current window

Population Stability Index

KL divergence

Significant drift alarm

Business metrics

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, jab hum model train karte hain to hum maan lete hain ki future bhi past jaisa hi rahega — yaani data ka distribution P(X,Y)P(X,Y) stable rahega. Par real duniya badalti rehti hai: users ki behaviour, prices, fraud ke tarike, sab. Drift detection ka kaam hai alarm bajana jab duniya itni badal jaye ki purana model bharosa ke layak na rahe. Trick ye hai: P(X,Y)=P(YX)P(X)P(X,Y) = P(Y|X)\,P(X). Bas yeh poochho — kaun sa factor badla?

Agar sirf inputs badle (P(X)P(X)), yani naye type ke customers aa gaye but rule same hai (25 saal ka banda utni hi default karta hai jitna pehle) — to ye data drift / covariate shift hai. Agar rule khud badal gaya (P(YX)P(Y|X)), jaise recession aa gayi aur ab wahi banda zyada default karta hai — to ye concept drift hai. Fix bhi alag hai: data drift me monitoring/reweighting kaafi ho sakta hai, par concept drift me aksar naye labels ke saath retrain karna padta hai.

Detect kaise karein? Input side pe hum reference window aur current window ko compare karte hain. PSI ((ciri)ln(ci/ri)\sum (c_i-r_i)\ln(c_i/r_i)) proportions ka surprise measure karta hai — 0.25 se upar matlab serious drift. Continuous features ke liye KS test (do CDF ke beech ka sabse bada gap), categorical ke liye chi-square. Concept drift ke liye labels chahiye — hum error rate track karte hain (DDM me 2σ pe warning, 3σ pe drift alarm). Yaad rakho: statistical significance aur practical importance alag cheez hain — millions rows me chhoti si shift bhi p-value flag kar degi, isliye hamesha effect size (PSI magnitude) aur business threshold dono dekho.

Go deeper — visual, from zero

Test yourself — MLOps & Deployment

Connections