When the Data Moves

Catching model drift before it costs you

Aniss Sahraoui

DATA 607 · Data Science in Context

December 2026

A model that passed its test

Project 4 spam filter (lasso regression)

  • Held-out test emails: 86.5% of spam caught
  • Accuracy 96.7%, only 1.5% of real email flagged
  • Ready to deploy?

Same filter, second collection of the same public corpus

  • Only 79.1% of spam caught
  • 275 spam emails let through
  • Nothing in the code changed. The data did.

A test score is a snapshot. The world a model runs in keeps moving.

Three ways the data moves

Type What changes Example from the spam filter
Covariate shift The inputs, P(X) More HTML email, more exclamation marks
Label shift The mix of outcomes, P(Y) Spam went from 15% to 48.7% of emails
Concept drift What the inputs mean, P(Y given X) A phrase that was harmless becomes a spam trick


Shift only matters when it hurts performance, but you often learn about performance last: labels arrive late, or never.

Why businesses care

Zillow Offers, 2021

  • Pricing models bought homes to resell
  • Q3 2021: $304 million inventory write-down
  • Program shut down; about 25% of staff cut
  • CEO: forecasting home prices was far more unpredictable than expected

Pandemic, 2020

  • Retail, inventory and fraud models trained on “normal” behavior started to misfire
  • Companies put humans back in the loop

Where monitoring is routine

  • Credit scoring: the population stability index (PSI) is a standard check that today’s applicants still look like the ones the model was built on
  • Fraud and spam: the other side adapts on purpose, so drift is built in
  • Demand forecasting: prices, seasons and promotions move the target

The cost is silent: a drifting model doesn’t crash, it just makes worse decisions.

R example: a population stability index

PSI compares how a variable is spread across bins then versus now.

psi <- function(expected, actual, bins = 10) {
  # bin edges from the reference data (deciles)
  cuts <- unique(quantile(expected, seq(0, 1, length.out = bins + 1)))
  cuts[c(1, length(cuts))] <- c(-Inf, Inf)
  e <- tabulate(cut(expected, cuts), length(cuts) - 1) / length(expected)
  a <- tabulate(cut(actual,   cuts), length(cuts) - 1) / length(actual)
  e <- pmax(e, 1e-4); a <- pmax(a, 1e-4)   # avoid log(0)
  sum((a - e) * log(a / e))
}

psi(training$n_exclaim, later$n_exclaim)
[1] 0.1766474

Common rule of thumb: below 0.1 stable · 0.1 to 0.25 watch · above 0.25 act

The alarm rings before the labels arrive

Share flagged as spam: 14.2% on the test set vs 38.7% on the later collection. No labels needed to see that.

What to do about it

A monitoring checklist

  1. Inputs: PSI on key features every week
  2. Outputs: score distribution and share flagged, no labels needed
  3. Performance: recall and false positives as labels arrive
  4. Triggers: decide in advance which number means retrain
  5. Retrain and compare: new model must beat the old one on recent data

Did retraining help the spam filter?

Model Spam caught (other half)
Trained on first collection 79.1%
Retrained with half the later emails 94.2%


Retraining fixed most of the gap, but only because the drift was noticed.

Learning path

Step Resource Why
1 Chip Huyen, Data Distribution Shifts and Monitoring (free post; chapter 8 of Designing Machine Learning Systems, O’Reilly 2022) Best plain-language start
2 Moreno-Torres et al. (2012), “A unifying view on dataset shift in classification,” Pattern Recognition Clear definitions of each type
3 Gama et al. (2014), “A survey on concept drift adaptation,” ACM Computing Surveys Detection and adaptation methods
4 Rabanser, Günnemann & Lipton (2019), “Failing Loudly,” NeurIPS Which drift tests actually work
5 Breck et al. (2017), “The ML Test Score,” IEEE Big Data Production checklist, incl. monitoring
6 vetiver for R: model monitoring Hands-on: track metrics over time in R

Takeaways

  1. A model’s test score describes the past. Production data keeps moving.
  2. Drift costs money silently: Zillow, pandemic forecasting, missed spam.
  3. You can watch inputs and outputs without labels: ten lines of R for PSI.
  4. Decide your retraining trigger before you need it.


Slides and code: GitHub: AnissSahraoui/DATA607, folder Week13/data_science_in_context