5.3.13 · D2MLOps & Deployment

Visual walkthrough — Data drift and concept drift detection

2,388 words11 min readBack to topic

Step 1 — Two piles of data, one honest question

WHY start here. You never see the true distribution — only samples. So drift detection is honestly just: lay two heaps of numbers side by side and ask "same shape or not?" Everything technical below is a careful way of answering that one plain question.

PICTURE. Two clouds of dots for one feature (say, applicant age). The reference cloud sits low; the current cloud has drifted right. Same axis, different pile-up.

Figure — Data drift and concept drift detection

Step 2 — Turn each pile into bars (binning)

WHY bin at all? Raw dots are hard to compare. But if both piles use the same bin edges, then "shape" becomes "the list of bar heights," and comparing two shapes becomes comparing two lists of numbers — something arithmetic can chew on.

PICTURE. The two dot clouds from Step 1 are now two histograms sharing identical bin edges: reference bars in one colour, current bars in another, standing in the same slots.

Figure — Data drift and concept drift detection

Step 3 — From counts to proportions (make piles comparable)

WHY proportions and not counts. We care about shape, not size. Fractions strip out how many samples you happened to collect and keep only "what share of the pile sits here." Now both piles live on the same -to- footing.

PICTURE. The two histograms re-scaled so each one's bars add up to a full unit of height — same silhouettes as Step 2, but now directly stackable against each other.

Figure — Data drift and concept drift detection

Step 4 — How "surprised" is one bin? Enter the log-ratio

WHY a ratio, not a difference? A difference like treats " vs " the same as " vs ". But doubling a bin's share (going from to ) is a big relative event; adding to a bin is a shrug. Ratios capture relative change — the thing that actually signals drift.

WHY the logarithm of the ratio? Look at the picture: a ratio of (doubled) and a ratio of (halved) are equally dramatic surprises, but as plain ratios they sit at wildly different distances from ( vs ). The (natural log) is the tool that answers "how many e-foldings of change is this?" — and it makes doubling and halving symmetric: and , mirror images across zero. That symmetry is exactly what "surprise" should have.

PICTURE. One bin, drawn three ways: current below reference ( negative), current equal (), current above ( positive). The curve passing through shows how ratios fold into a signed surprise.

Figure — Data drift and concept drift detection

Step 5 — Fix the asymmetry: weight the log-ratio by the actual gap

WHY multiply by ? Two payoffs at once:

  1. It down-weights trivial bins. A tiny bin has a tiny gap , so its contribution shrinks no matter how dramatic its ratio.

  2. It forces every term positive. Here is the beautiful part — watch the signs:

    • If the bin grew (): gap is , and is also . Product: .
    • If the bin shrank (): gap is , and is also . Product: .
    • If the bin is unchanged (): gap is . Product: .

    The gap and the log-ratio always share the same sign, so their product can never be negative. Drift can only add up, never cancel.

PICTURE. The sign-agreement drawn explicitly: a "grew" bin (both arrows up-right, green product) and a "shrank" bin (both arrows down-left, still positive product) — showing why the term is a valid distance-like quantity.

Figure — Data drift and concept drift detection

Step 6 — Sum over all bins: the whole PSI

WHY sum? Each is an independent "amount of surprise" in bin . Adding them gathers the whole shape-mismatch into one score. Because no term is negative, a big surprise in any region cannot be hidden by calm elsewhere — the alarm can only get louder.

PICTURE. A row of the per-bin bars from Step 5 being stacked into a single total column labelled PSI, with the rule-of-thumb thresholds (, ) drawn as horizontal lines.

Figure — Data drift and concept drift detection

Step 7 — The degenerate case: an empty bin ( or )

WHY it happens & WHY it matters. A brand-new region of feature space appearing (or an old region vanishing) is genuinely infinite "surprise" — the model has literally never seen it. But an infinite score is useless for a threshold, and one empty bin caused by small samples shouldn't nuke your whole metric.

THE FIX (standard practice). Add a tiny floor (e.g. ) to any empty proportion before taking the log, or merge bins so none are empty. This keeps PSI finite while still reporting a large-but-usable value for genuinely new regions.

PICTURE. A bin where reference is flat-zero and current pokes up; the arrow shooting to infinity, then the -floor clamping it down to a big-but-finite bar.

Figure — Data drift and concept drift detection

Step 8 — Walk the worked example on the picture

WHY re-visit it. Numbers only stick once you watch them come from geometry. Each bin's contribution is literally "gap log-ratio," and the picture shows which bins are shouting.

  • Bin 1 shrank (): gap , log , product positive . Sign-agreement in action (Step 5).
  • Bin 2 unchanged: contributes exactly .
  • Bin 3 grew (, doubled): the doubling gives , product .
  • Total → moderate-to-significant. Investigate before triggering retraining.

PICTURE. The three bins with each term annotated on top of its bar; bins 1 and 3 lit up, bin 2 dark, and the running sum climbing to against the threshold lines.

Figure — Data drift and concept drift detection

The one-picture summary

Figure — Data drift and concept drift detection
Recall Feynman retelling — the whole walk in plain words

Imagine you have two boxes of the same toy sorted into the same shelves. The old box is how the world looked when you trained your model; the new box is today. You want one number for "did the toys move shelves?"

First you count what fraction sits on each shelf in each box — that's (old) and (new), using fractions so a bigger box doesn't cheat. For each shelf you ask two things: which way did it change and by how much? (that's the gap ) and how dramatic is the change relative to before? (that's the log-ratio , which treats "doubled" and "halved" as equally shocking). You multiply them — and magic: because a shelf that grew has both pieces positive, and a shelf that shrank has both pieces negative, the product is always positive. Surprise can only pile up, never cancel. Add every shelf's surprise and you get PSI. Under nothing moved; over the toys really rearranged — go check your model. And if a shelf is suddenly used that was empty before, the log tries to explode to infinity, so you tuck a tiny cushion under it to keep the number sane.


Connections