5.3.13 · D3MLOps & Deployment

Worked examples — Data drift and concept drift detection

2,749 words12 min readBack to topic

Before we start, one word we'll use constantly: a bin is a bucket. We chop a numeric feature's range into a few intervals (say "0–20 years old", "20–40", "40+") and count how many data points land in each. The proportion of a bin is (points in that bin) ÷ (total points). All the and symbols below are just these proportions — reference vs current.


The scenario matrix

Every drift computation you'll ever do is one of these cells. The worked examples that follow are tagged with the cell they cover.

# Case class What's tricky Example
A No drift () Must return exactly 0 Ex 1
B Mass shifts up in one bin () Sign check on log-ratio Ex 2
C Mass shifts down () Term still positive Ex 2
D Zero-count bin ( or ) — degenerate! Ex 3
E Continuous shift, KS Where is the max gap? Ex 4 (figure)
F Categorical mix, chi-square Observed vs expected counts Ex 5
G Concept drift alarm (DDM) 2σ vs 3σ crossing Ex 6 (figure)
H Limiting behaviour PSI as bins → identical/opposite Ex 7
I Real-world word problem Which test? which fix? Ex 8
J Exam twist — data drift but NO accuracy loss Don't retrain reflexively Ex 9

We use these tools from the parent: PSI/KL, the KS statistic, chi-square, and DDM.


Example 1 — Cell A: the no-drift baseline


Example 2 — Cells B & C: one bin up, one bin down


Example 3 — Cell D: the zero-count degenerate case


Example 4 — Cell E: KS statistic, finding the max gap

Figure — Data drift and concept drift detection

The empirical CDF is just "what fraction of my sample is ." It's a staircase that steps up by at each data point.

  1. Build : steps at , each . So as passes each point. Why this step? KS compares the two staircases; we need their heights.
  2. Build : steps at . , but just before 3 it is .
  3. Scan for the biggest vertical gap . Evaluate at each reference point:
    • At : , → gap .
    • At : , → gap .
    • At (just after): , → gap . Why this step? "" means the worst-case gap; on staircases the max always occurs at a jump point, so we only check those.
  4. .

Verify: A pure +2 shift of a 5-point sample leaves of points "unmatched" at the extreme, i.e. gap . Matches. Large KS flags a clear right-shift. ✓


Example 5 — Cell F: chi-square on a categorical feature


Example 6 — Cell G: DDM concept-drift alarm

Figure — Data drift and concept drift detection
  1. Current spread . Why this step? Each prediction is right/wrong — a Bernoulli. The error rate over of them wobbles with the standard deviation of a proportion. We need this wobble to know if is "far".
  2. The statistic: . Why this step? DDM tracks the pessimistic edge (rate plus its own noise), not just the rate.
  3. Warning threshold: . Is ? Yes → past Warning.
  4. Drift threshold: . Is ? YesDRIFT. Why 3σ? If errors were just noise around , exceeding 3 standard deviations is a ~0.1% event — too rare to be luck. So we call it real degradation and trigger retraining.

Verify: , so both thresholds are crossed → Drift state (the stronger). Consistent: a jump from 10% to ~18% pessimistic error is well beyond 3σ. ✓


Example 7 — Cell H: limiting behaviour of PSI


Example 8 — Cell I: real-world word problem


Example 9 — Cell J: exam twist (drift without accuracy loss)


Active recall

Cover the answers first.

Every empty bin makes raw PSI equal to what value, and what's the fix?
; replace zero proportions with a tiny and renormalise.
On staircase (empirical) CDFs, the KS max gap always occurs where?
at a jump point (a data value) — so you only check those.
In chi-square, comes from where?
reference proportions scaled by the current sample size : .
DDM's Drift threshold is which multiple of above ?
(Warning is ).
If PSI is high but shadow accuracy is unchanged, do you retrain?
No — pure covariate shift with intact ; monitor instead.
Recall Scenario-matrix self-quiz
  1. Which cell is " danger"? (Answer: D) 2. Which two cells prove PSI terms stay positive whether mass leaves or arrives? (B and C) 3. Which cell shows PSI has no upper bound? (H) 4. Which cell fires the 3σ retrain trigger? (G)

Connections