Data drift and concept drift

When the world changes, models decay; measure the change in the inputs with the population stability index (PSI).

Lesson 61 of 6614 minIntermediate

You will learn to

  • Tell data drift from concept drift
  • Compute and read the population stability index (PSI)
  • Choose a reference baseline and a window, and enough rows to avoid false alarms

Before this lesson

Intuition

A weather forecaster trained on decades of data suddenly faces a changing climate. Nothing is wrong with her method, but the world no longer looks like the examples she learned from.

Models are in the same position. They learn from a snapshot and then work in a world that keeps moving. We separate two kinds of change.

  • Data drift (also called covariate shift): the inputs change. Customers are younger, prices are higher, a sensor is recalibrated. The relationship between inputs and outcome may still hold, but the model now works on regions of the input space where it saw few examples.
  • Concept drift: the relationship between inputs and the target changes. The same customer profile used to mean "will stay" and now means "will leave", because a competitor launched a cheaper plan. The inputs may look identical.

Data drift can be measured right away, because it only needs the inputs the endpoint receives. Concept drift can only be confirmed with true outcomes, which arrive late. This is why input drift checks are the standard early warning.

Picture it

0%10%20%12345678910ReferenceCurrentBuckets of one feature, low to high (each holds 10% of the reference)Share of rows
One feature split into ten buckets that each held 10% of the reference rows. The current window has fewer low values and more high values. The more the grey and blue bars disagree, the higher the PSI.

The math

The Population Stability Index compares two distributions of the same variable, split into BB buckets. Let rir_i be the share of the reference rows in bucket ii and cic_i the share of the current rows. Then

PSI=∑i=1B(ci−ri) ln⁡ ⁣(ciri)\mathrm{PSI} = \sum_{i=1}^{B} (c_i - r_i)\,\ln\!\left(\frac{c_i}{r_i}\right)

Every term is zero or positive: when ci>ric_i > r_i both factors are positive, and when ci<ric_i < r_i both are negative. So PSI is 0 only when all shares match, and it grows as they move apart.

Buckets. For a numeric feature, the bucket edges are the quantiles of the reference data, so each of the B=10B = 10 buckets holds 10% of the reference. For a category feature, each common level gets its own bucket.

Common reading guidance: below 0.1 is stable, 0.1 to 0.2 is a moderate shift, and above 0.2 is a significant shift. Treat these as conventions, not laws.

Categories. For a categorical feature, mlflow also reports Cramer's V, a number between 0 and 1 that measures how strongly the category frequencies in two windows are associated: 0 means the same mix, and values near 1 mean very different mixes.

Noise and sample size. If nothing changed, PSI is still not exactly 0, because samples are random. With nrefn_{\mathrm{ref}} and ncurn_{\mathrm{cur}} rows, the PSI of unchanged data is approximately

(1nref+1ncur)χB−12\left(\frac{1}{n_{\mathrm{ref}}} + \frac{1}{n_{\mathrm{cur}}}\right)\chi^2_{B-1}

where χB−12\chi^2_{B-1} is a chi-squared random number with B−1B-1 degrees of freedom. Its typical value is about 9 for 10 buckets. With 200 rows per side the factor is 0.01, so a typical no-change PSI is about 0.09, and a feature with no real change still crosses 0.2 about 2% of the time. Across 30 features, that is roughly a coin flip that at least one alerts. With 500 rows per side the factor is 0.004 and a typical value is about 0.04. More rows means a cleaner signal.

Worked example

The reference window held 10 equal buckets of 10% each. In the current window the shares are

Bucket12345678910
Reference rir_i0.100.100.100.100.100.100.100.100.100.10
Current cic_i0.040.060.070.080.090.110.120.130.140.16

The current shares add up to 1.00. The term of each bucket is (ci−ri)ln⁡(ci/ri)(c_i - r_i)\ln(c_i / r_i):

  • Bucket 1: (0.04 - 0.10) x ln(0.4) = (-0.06)(-0.9163) = 0.0550
  • Bucket 2: (-0.04) x ln(0.6) = (-0.04)(-0.5108) = 0.0204
  • Bucket 3: (-0.03) x ln(0.7) = 0.0107
  • Bucket 4: (-0.02) x ln(0.8) = 0.0045
  • Bucket 5: (-0.01) x ln(0.9) = 0.0011
  • Bucket 6: (0.01) x ln(1.1) = 0.0010
  • Bucket 7: (0.02) x ln(1.2) = 0.0036
  • Bucket 8: (0.03) x ln(1.3) = 0.0079
  • Bucket 9: (0.04) x ln(1.4) = 0.0135
  • Bucket 10: (0.06) x ln(1.6) = 0.0282

The sum is PSI = 0.146, a moderate shift. The largest contributions come from the ends: the lowest bucket lost more than half its share, and the highest gained 60%. With the default threshold of 0.2 this feature would not raise an alert yet, but it is worth watching. If it stays at 0.146 for weeks, that is a stable new normal. If it grows, it is a trend.

A feature-by-feature check matters. A model with 30 features can look calm on average while two key features drift strongly, which is why mlflow lets you set the threshold per feature.

How mlflow does it

  • Reference. The first predictions logged after the current model went live (500 by default). The reference does not slide, so a long, slow shift keeps showing as drift instead of becoming the new normal. While there are too few logs, the training data of the model is used. After a rollback or a retrain promotion the reference restarts.
  • Current window. The latest predictions (500 by default).
  • Scoring. Numeric features get a 10-bucket PSI on reference quantiles. Low-cardinality numeric features and categories use frequency buckets, and a category must hold at least 5% of the reference to get its own bucket. Features where no category does are reported as not monitored.
  • Minimum values. A feature with fewer than the minimum values per side (500 by default) is not scored, to avoid false alerts.
  • Thresholds and alerts. The default PSI threshold is 0.2, adjustable per feature. A feature over its threshold opens one alert per incident, which notifies workspace webhooks (and email when configured), and the alert resolves after a set number of clean checks.
  • Check cadence. Use Check now, or schedule checks on the Monitor tab.

Common mistakes

  • Confusing data drift with a broken model. Drift means inputs moved, not that accuracy fell. It is a reason to look, not proof of failure.
  • Using a tiny window. With a few hundred rows, noise alone breaches 0.2 on models with many features. Use enough rows per side.
  • Letting the reference slide. If the baseline follows the data, slow drift never shows. Pin the reference to a known-good period.
  • Treating 0.2 as universal. It is a convention. High-stakes features may need a lower threshold, noisy ones a higher one.
  • Ignoring concept drift. Perfect input stability says nothing about whether the rule changed. Compare predictions with true outcomes whenever they arrive.

Try it in mlflow

Read a drift report

  1. Open Deployments, click an endpoint that has received predictions, and open the Monitor tab.
  2. In Drift thresholds, note the PSI threshold and the number of predictions used for the reference and the current window.
  3. Choose Check now, then read the Drift reports and Drift alerts lists.
  4. Open a report and read the Feature drift snapshot: which features moved the most?
Open in mlflow

Read in the docs

Check your understanding

  1. 1. Customers start paying in a new currency, so the 'amount' column has much larger numbers than in training. The link between amount and fraud is unchanged. What is this?
  2. 2. Which situation gives a PSI of exactly 0?
  3. 3. Why does mlflow need hundreds of values per side before it scores a feature?