Chapter 41 of 42 · ~16 min read & lab+60 XP
Chapter 41 · Machine Learning

Data Drift vs. Concept Drift: PSI, KS-Test & Production Model Monitoring

Why every deployed ML model silently decays over time, how to separate Covariate Shift from Concept Drift, and how PSI & KS-tests trigger retraining

What Is It?

Data Drift (Covariate Shift) happens when live input distributions P(X) change over time, while Concept Drift happens when the true relationship P(y|X) between inputs and outcomes changes — and ML Monitoring tracks both continuously in production.

Why Is It Required?

Traditional software crashes loudly with 500 errors; ML models fail SILENTLY by returning confident wrong predictions while customer behavior or fraud tactics evolve.

Everyday Analogy: Data Drift = suddenly getting twice as many winter-coat shoppers in July; Concept Drift = shoppers who used to love skinny jeans suddenly switching to baggy jeans overnight.
Why ML Engineers & Data Scientists Actually Need This

Deploying a model is Day 1, not the finish line — unmonitored ML models degrade relentlessly as markets, users, and adversaries change.

ML / AI Engineer

Monitoring prediction distributions, null-rate spikes, and PSI catches broken upstream ETL pipelines within minutes instead of quarters.

Data Scientist

Recognizing Concept Drift (e.g., COVID lockdowns changing travel patterns) tells you to weight recent data higher or retrain rather than blaming the model code.

Interview & Debug Edge

Top MLOps interview question: 'How do you detect model degradation when ground-truth labels take 60 days to arrive?'

Step 0 · Test Your Gut Before Any Math!

A spam filter was trained in 2022. In 2025, scammers start using brand-new AI-written phishing templates so emails that used to look legitimate (X) are now spam (y=1). What type of drift is this?

What You Will Master in This Chapter
  • Distinguish Data Drift (P(X) shifts), Label Drift (P(y) shifts), and Concept Drift (P(y|X) shifts) with concrete examples.
  • Compute and interpret the Population Stability Index (PSI: <0.10 stable, 0.10–0.25 moderate, >0.25 severe drift).
  • Monitor input drift immediately when ground-truth labels are delayed by weeks (e.g., 90-day loan defaults).
  • Design safe automated retraining triggers paired with shadow/canary rollouts.
Plain-English Symbol Decoder · Click Any Symbol Before We Begin
1 / 2
PSI=∑b=1B(ab−eb)ln⁡(abeb)\text{PSI} = \sum_{b=1}^B (a_b - e_b)\ln\left(\frac{a_b}{e_b}\right)Say aloud:“Population Stability Index”
Plain-English Meaning
Measures how far live bin proportions a_b drifted from baseline training bin proportions e_b.
Everyday Example
PSI < 0.10 = green; 0.10–0.25 = yellow warning; > 0.25 = red alert (retrain/investigate!).
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Think of ML monitoring as three concentric radar rings: (1) Data Health (null spikes, schema breaks), (2) Input & Prediction Drift (PSI / KS-test — works even when labels are delayed!), and (3) Ground-Truth Accuracy (live AUC/RMSE once labels arrive).

1. The 3 Types of Drift & How to Catch Them

Drift TypeWhat Changed?Detect Without Labels?Example
Data Drift (Covariate Shift)P(X)P(X)Yes (PSI, KS-test, Wasserstein)Upstream bug changes USD to cents, or user demographics shift
Prediction / Label DriftP(y^)P(\hat{y}) or P(y)P(y)Yes for P(y^)P(\hat{y})Sudden jump in predicted fraud rate from 2% to 18%
Concept DriftP(y∣X)P(y \mid X)No (needs delayed labels or proxy KPIs)Fraudsters invent new attack patterns; consumer tastes shift
“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Not always! If an unimportant feature drifted, accuracy might stay fine. Conversely, if a top SHAP feature shows PSI > 0.25, investigate immediately — it is almost always an upstream data bug or major market shift.

Interactive Visual Lab
Lab Challenge: Trace how monitoring and retraining close the production ML lifecycle loop.
Interactive Deep Lab · Production ML Lifecycle Checklist

Activate All 5 Pillars of a Ship-Ready ML Project

Readiness: 40%
Click each missing stage above to complete your end-to-end production ML lifecycle!
Intuition Takeaway: Monitor schema/nulls, feature & prediction PSI (>0.25 = alert), and delayed ground-truth KPIs together so you catch both upstream data breaks and silent Concept Drift before revenue suffers.
Production NumPy & PyTorch Code Patterns
import numpy as np

# Population Stability Index (PSI) From Scratch to Monitor Live Data Drift
def compute_psi(expected: np.ndarray, actual: np.ndarray, bins: int = 5) -> float:
    edges = np.quantile(expected, np.linspace(0, 1, bins + 1))
    edges[0], edges[-1] = -np.inf, np.inf
    e_pct = np.histogram(expected, bins=edges)[0] / len(expected)
    a_pct = np.histogram(actual,   bins=edges)[0] / len(actual)
    e_pct = np.clip(e_pct, 1e-6, 1.0)
    a_pct = np.clip(a_pct, 1e-6, 1.0)
    return float(np.sum((a_pct - e_pct) * np.log(a_pct / e_pct)))

rng = np.random.default_rng(0)
train_feat = rng.normal(50, 10, size=1000)
live_ok    = rng.normal(50.5, 10, size=1000)
live_drift = rng.normal(62, 12, size=1000)   # severe mean + spread shift!

print(f"Healthy live PSI: {compute_psi(train_feat, live_ok):.4f} (< 0.10 green)")
print(f"Drifted live PSI: {compute_psi(train_feat, live_drift):.4f} (> 0.25 RED ALERT!)")
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Assuming automated blind retraining on a weekly cron solves all drift.
Best Practice: Blindly retraining on corrupted upstream data bakes the bug into the model! Always gate retraining with data-quality assertions and shadow/canary evaluation.
Chapter Mastery Check (+60 XP)
Score: 0 / 1
1You compute PSI = 0.42 on your #1 most important input feature 2 days after an upstream app release. What does PSI > 0.25 signal?

Apply What You Learned — Solve Matching Coding Problems