Skip to content

Drift that no single column shows

Two features can each look unchanged while the way they combine has moved. Learn what energy distance, MMD and a classifier two-sample test measure, and how to read them together.

Advanced ~12 min10 steps

You will be able to

  • Explain how the joint distribution can move while every column stays the same
  • Describe what energy distance, MMD and the classifier two-sample test each measure
  • Read a permutation p-value with a Holm correction, and keep it apart from the size of a shift
  • Use the per-feature separation to tell where a joint shift comes from

Read first

01

What can one column miss?

Predict

Predict first

Two features were unrelated in training. In new data, the second always copies the first. Each one, taken alone, has exactly the same distribution as before. What does PSI on each feature say?

PSI flags both featuresPSI flags one featurePSI sees nothing
Reveal

PSI sees nothing. It looks at one column at a time, and neither column moved. Only the way they combine has changed, and that's the part a model may rely on. This is joint driftJoint driftA change in how features combine, which can happen while each feature on its own looks unchanged.. The app's test suite includes this exact case: the joint tests catch it, and each feature's own separation stays low.

02

Three ways to compare clouds of rows

Read

Each test treats a row as a point, and compares the training cloud with the new one.

TestWhat it asksNo shift looks like
Energy distanceEnergy distanceTwice the mean distance between samples minus the mean distances within each; zero only when the distributions are equal.Are rows across the two samples farther apart than rows within them?Close to 0
MMDMaximum mean discrepancyThe distance between two distributions' average kernel embeddings; zero when they are equal.Do the samples differ on average, in a similarity that spots any kind of difference?Close to 0
Classifier two-sample testClassifier two-sample testIf a classifier can tell new rows from training rows, the data has shifted; its AUC measures by how much.Can a classifier tell which sample a row came from?AUC near 0.5

Both samples are encoded with the training data's own scales first: numbers as z-scores, and top categories as indicators.

03

Where the p-value comes from

Explore

Suppose the two samples came from one distribution. Then "training" and "new" are only labels, and you can shuffle them.

BExplorable · Permutation shuffler

Could a difference this large come from shuffling the labels alone?

Shuffle the labels a thousand times. How often will the shuffled difference be as large as the real one?

How sure?

Data

Statistic

+30 on the last value of the second group.

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.

The joint tests work the same way, with rows in place of animals. They shuffle the labels 199 times and recompute each statistic. With that many shuffles, the smallest possible p is:

0+1199+1=0.005\frac{0 + 1}{199 + 1} = 0.005

Since three tests run together, Holm's correction across them decides whether the features moved jointly.

04

Evidence and size are different questions

Read

On a big table, a tiny shift can give a small p. So read the classifier's AUC as the size of the shift: 0.52 and 0.85 can both come with small p-values, and they mean very different things.

To keep the cost down, each side is capped at 1,000 rows, because these tests compare every pair of rows. So the p-values can't keep shrinking with table size, as a KS test's would.

05

Where is the shift?

Predict

Predict first

A joint test fires, with a small Holm p. The card's Separate best on their own line shows low values for every feature. What does that suggest?

One feature has moved a lotThe features moved in how they combineNothing moved: it's a false alarm
Reveal

The features have moved in how they combine. That line scores how well each feature alone separates the samples, from 0 to 1. A high value names a feature to inspect, and PSI will usually agree. Low values alongside a firing test point at a change in the relationships.

06

Read the card

In the app

Open a version's Drift tab and press Compare. Above the feature table, the joint card shows either The features moved jointly or No joint drift, with each test's statistic, p and Holm p.

Each monitor run does this too, so mv_drift = 1 works as an alert rule, and the classifier's AUC can be tracked over runs.

To switch it off for a model, turn off Test features jointly in Gates & policy. Versions registered before the reference sample existed have no joint test.

07

What would you do next?

Reflect

A joint test fires, the classifier AUC is 0.75, and no single feature stands out.

Which would you look at first: a scatter of the features the model relies on most, a change in how the data is collected, or the model's performance on newly labeled rows? Say why, and say what result would make you stop worrying.

08

Check your understanding

Checkpoint

Check yourself

A classifier trying to separate training rows from new rows gets an AUC of 0.50. What's the most direct reading?

Show the answer

Answer: a

An AUC of 0.5 is a coin flip. It doesn't prove the distributions are the same, and it says nothing about your model's accuracy on outcomes.

Check yourself

Which change could a joint test catch while PSI on every feature stays low?

Show the answer

Answer: a

The other two change a single column's distribution, which PSI sees directly.

Check yourself

Out of 199 shuffles, 1 gave a statistic at least as large as the observed one. What is the permutation p-value?

Show the answer

Answer: 0.01

Count the observed arrangement too: (1 + 1) / (199 + 1) = 0.01.

09

Compute it yourself

In the app

Here is energy distance with a permutation p-value on two columns. Use a sample of about 1,000 rows from each side, because the cost grows with the square of the row count.

Python
import numpy as np
import pandas as pd
from scipy.spatial.distance import cdist

cols = ["income", "age"]
train = pd.read_csv("train.csv")[cols].dropna()
new = pd.read_csv("new.csv")[cols].dropna()
mu, sd = train.mean(), train.std()
a, b = ((train - mu) / sd).to_numpy(), ((new - mu) / sd).to_numpy()

def energy(x, y):
    return 2 * cdist(x, y).mean() - cdist(x, x).mean() - cdist(y, y).mean()

obs = energy(a, b)
pool = np.vstack([a, b])
rng = np.random.default_rng(1)
B, hits = 199, 0
for _ in range(B):
    i = rng.permutation(len(pool))
    hits += energy(pool[i[: len(a)]], pool[i[len(a):]]) >= obs
print(round(obs, 4), (1 + hits) / (B + 1))
R
cols <- c("income", "age")
train <- na.omit(read.csv("train.csv")[, cols])
new <- na.omit(read.csv("new.csv")[, cols])
mu <- colMeans(train)
s <- apply(train, 2, sd)
pool <- rbind(scale(train, mu, s), scale(new, mu, s))
d <- as.matrix(dist(pool))

energy <- function(i, j) 2 * mean(d[i, j]) - mean(d[i, i]) - mean(d[j, j])

n <- nrow(train)
obs <- energy(1:n, (n + 1):nrow(pool))
set.seed(1)
B <- 199
perm <- replicate(B, {
  k <- sample(nrow(pool))
  energy(k[1:n], k[(n + 1):length(k)])
})
c(round(obs, 4), (1 + sum(perm >= obs)) / (B + 1))
10

Recap

Recap
  • The joint distribution can move while every column stays the same, and per-feature tests can't see that.
  • Energy distance, MMD and the classifier test compare clouds of rows, with permutation p-values and Holm across the three.
  • Read the classifier's AUC as size and the p-value as evidence.
  • Low per-feature separation with a firing test points at a change in how features combine.

Concepts in this lesson