Skip to content

Data drift: have the inputs moved?

Compute a PSI by hand, see why the app changes tests with the size of the training data, and learn what drift does and doesn't say about a model.

Applied ~13 min11 steps

You will be able to

  • Compute a population stability index from bin shares
  • Explain why large tables are judged by distance rather than by p-value
  • Control false alarms when many features are tested
  • Tell input drift apart from a fall in performance

Read first

01

A model only knows what it saw

Read

At registration, the version keeps a profile of its training rows: for each number, the deciles as bin edges, and for each category, its top levels with their shares.

DriftData driftThe data a model sees in use has moved away from the data it was trained on. is new data leaving that picture. It doesn't say the model got worse. It says the model is being asked about rows less like the ones it learned from, so its test score applies less directly.

02

Guess the shift

Predict

Predict first

A feature's four training bins each held a quarter of the rows. In new data they hold 10%, 20%, 30% and 40%. How would PSI rate that?

StableModerateMajor
Reveal

Moderate, though close to the line. The next step does the arithmetic. It looks like a big change, and PSI still doesn't call it major. Bands are conventions, so look at the bars as well as the label.

03

PSI by hand

Read

The population stability indexPopulation stability indexA summary of how much a variable's distribution has shifted between two periods. adds up, over bins, how much each share moved, weighted by the log of the ratio:

PSI=∑i(ci−ri) ln⁡ciri\text{PSI} = \sum_i (c_i - r_i)\,\ln\frac{c_i}{r_i}

For that feature, with ri=0.25r_i = 0.25 throughout:

(−0.15)ln⁡0.4+(−0.05)ln⁡0.8+(0.05)ln⁡1.2+(0.15)ln⁡1.6=0.228(-0.15)\ln 0.4 + (-0.05)\ln 0.8 + (0.05)\ln 1.2 + (0.15)\ln 1.6 = 0.228

The usual bands are below 0.1 stable, up to 0.25 moderate, and above that major. A bin that empties gets a small floor, so the log stays finite.

04

Why size changes the test

Explore

PSI measures size. A p-value measures evidence, which keeps growing with rows, whether or not the shift matters. This explorable shows the same effect with a normality test.

AExplorable · The normality-test paradox

Why is a normality test least helpful exactly when you might rely on it?

How often does Shapiro–Wilk reject this skew at n = 1,000?

0.50
How sure?
0.05
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Keep the departure mild, and compare how often the test rejects at n = 10 and at n = 1,000. With enough rows, it detects a skew too slight to matter.

A drift test does the same thing. On a large table, a KS test can flag a shift nobody would care about.

05

Which test decides

Read

So by default the app chooses by the size of the training data.

Training rowsNumbersCategoriesDrift when
Up to 1,000Kolmogorov–SmirnovKolmogorov–Smirnov testCompares distributions by the largest vertical gap (D) between their cumulative curves.Two-proportion z or χ²p < .05
MoreNormalized WassersteinWasserstein distanceHow far one distribution must be moved to match another, in the data's own units. Useful for measuring drift.Jensen–ShannonJensen–Shannon distanceA bounded distance between two sets of category shares; 0 means identical.Distance ≥ 0.1

The dataset counts as drifted when at least half of its features do. You can change all of these for a model under Gates & policy, in Drift policy.

06

Many features, many false alarms

Explore

Test 30 features at p < .05, and at least one is likely to be flagged by chance, even when nothing has moved.

BExplorable · The family-wise error rate

If you run many tests, how likely is at least one false alarm, and what does correcting cost?

Without correction, how often does this family produce at least one false alarm?

0.50
How sure?
20
3
3.0
0.050
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Set the real effects to zero and look at the chance of at least one false alarm. Then raise the number of tests.

In Drift policy, Across features can apply Benjamini–HochbergBenjamini–Hochberg procedureControls the false discovery rate by comparing sorted p-values with rising thresholds., which keeps the expected share of false alarms among flagged features under control. This matters most when p-values decide, so on small training sets.

07

Compare a dataset

In the app

Open a version's Drift tab, choose a dataset and press Compare. Start with the training data itself, {{dataset}} in the walkthrough: you should see no drift, which is a good check.

Then try new rows. Click a feature to see its training and current shares as paired bars. Over many runs, a monitor draws the same numbers as a timeline.

Drift over timeWhich features of the scoring data are drifting away from the training data, and since when?
View data
scoring weekPSIfeature
1,777,852,800,0000.0343income
1,777,852,800,0000.0024tenure
1,777,852,800,0000.0272region
1,777,852,800,0000.0397age
1,777,852,800,0000.0131channel
1,777,852,800,0000.0399device
1,777,852,800,0000.0362balance
1,777,852,800,0000.0064visits
1,778,457,600,0000.0002income
1,778,457,600,0000.0230tenure
1,778,457,600,0000.0387region
1,778,457,600,0000.0440age
1,778,457,600,0000.0070channel
1,778,457,600,0000.0139device
1,778,457,600,0000.0435balance
1,778,457,600,0000.0247visits
1,779,062,400,0000.0218income
1,779,062,400,0000.0248tenure
1,779,062,400,0000.0293region
1,779,062,400,0000.0342age
1,779,062,400,0000.0385channel
1,779,062,400,0000.0227device
1,779,062,400,0000.0345balance
1,779,062,400,0000.0118visits
1,779,667,200,0000.0204income
1,779,667,200,0000.0164tenure
1,779,667,200,0000.0094region
1,779,667,200,0000.0203age
1,779,667,200,0000.0158channel
1,779,667,200,0000.0158device
1,779,667,200,0000.0120balance
1,779,667,200,0000.0087visits
1,780,272,000,0000.0398income
1,780,272,000,0000.0285tenure
1,780,272,000,0000.0144region
1,780,272,000,0000.0212age
1,780,272,000,0000.0140channel
1,780,272,000,0000.0011device
1,780,272,000,0000.0523balance
1,780,272,000,0000.0044visits
1,780,876,800,0000income
1,780,876,800,0000.0217tenure
1,780,876,800,0000.0202region
1,780,876,800,0000.0237age
1,780,876,800,0000.0228channel
1,780,876,800,0000.0120device
1,780,876,800,0000.0319balance
1,780,876,800,0000.0148visits
1,781,481,600,0000.0193income
1,781,481,600,0000.0270tenure
1,781,481,600,0000.0422region
1,781,481,600,0000.0267age
1,781,481,600,0000channel
1,781,481,600,0000.0179device
1,781,481,600,0000.0352balance
1,781,481,600,0000.0169visits
1,782,086,400,0000.0234income
1,782,086,400,0000.0524tenure
1,782,086,400,0000.0305region
1,782,086,400,0000.0341age

First 60 of 208 rows.

08

Drift isn't the same as decay

Reflect

Two different things can go wrong:

  • Inputs move, and the model is still right about the rows it sees. Accuracy may hold.
  • The link changes: the same inputs now lead to other outcomes. This is concept driftConcept driftThe link between inputs and outcome changes, so a model's accuracy falls even though its inputs look the same., and input tests can't see it, because inputs look the same.

So drift is a reason to look, and no drift isn't a clean bill of health.

For a model of yours, which feature would worry you most if it moved? Is that feature one the model leans on?

09

Check your understanding

Checkpoint

Check yourself

A binary feature had training shares of 50% and 50%. Now they are 60% and 40%. What is its PSI? Give three decimals.

Show the answer

Answer: 0.0405

(0.60 − 0.50) ln(0.60 / 0.50) + (0.40 − 0.50) ln(0.40 / 0.50) = 0.0182 + 0.0223 = 0.041. That's stable, by the usual bands.

Check yourself

A model trained on 2 million rows. A KS test on age gives p < .001, but the normalized Wasserstein distance is 0.01. What's the sensible reading?

Show the answer

Answer: b

With millions of rows, trivial shifts reach significance. That's why the app judges large training sets by distance.

Check yourself

No feature has drifted, but the model's accuracy on newly labeled rows has fallen. What's the most likely explanation?

Show the answer

Answer: b

That's concept drift. It's why you also monitor performance once outcomes arrive, as the next lessons show.

10

Do it on your own data

In the app

Compare a recent extract with a model's training data, and sort out which flagged features the model actually uses. To see the arithmetic for yourself, compute a PSI by hand.

Python
import numpy as np
import pandas as pd

def psi(reference, current, eps=1e-4):
    reference, current = reference.dropna(), current.dropna()
    edges = np.unique(np.quantile(reference, np.arange(1, 10) / 10))
    bins = np.r_[-np.inf, edges, np.inf]
    r = np.maximum(np.histogram(reference, bins)[0] / len(reference), eps)
    c = np.maximum(np.histogram(current, bins)[0] / len(current), eps)
    return float(np.sum((c - r) * np.log(c / r)))

print(psi(pd.read_csv("train.csv")["income"], pd.read_csv("new.csv")["income"]))
R
psi <- function(reference, current, eps = 1e-4) {
  edges <- unique(quantile(reference, (1:9) / 10, na.rm = TRUE))
  bins <- c(-Inf, edges, Inf)
  shares <- function(x) as.numeric(table(cut(x, bins))) / sum(!is.na(x))
  r <- pmax(shares(reference), eps)
  now <- pmax(shares(current), eps)
  sum((now - r) * log(now / r))
}

psi(read.csv("train.csv")$income, read.csv("new.csv")$income)

These are close to the app's calculation, which also adds a bin for missing values when either side has any.

11

Recap

Recap
  • PSI measures how far bin shares moved. The bands are conventions, not tests.
  • On large tables, p-values flag trivial shifts, so the app judges those by distance.
  • Testing many features creates false alarms; Benjamini–Hochberg limits them.
  • Drift is a reason to look. It isn't the same as decay, and its absence doesn't rule decay out.

Concepts in this lesson