5.3.15 · D2MLOps & Deployment

Visual walkthrough — Model retraining pipelines

1,966 words9 min readBack to topic

We are answering one question the whole way: "Has the world my model was trained on quietly changed?" — and turning that vague worry into a single number a machine can watch.


Step 1 — Two piles of data, drawn as histograms

WHAT. We have two collections of numbers for one feature (say, customer age). One collection is the data the model was trained on ("expected"). The other is recent production data ("actual"). We chop the number line into equal slices called bins, and count how many samples fall in each.

WHY. Comparing raw clouds of thousands of points is hopeless. Binning turns each cloud into a small bar chart — a shape we can compare bar-by-bar. A bin is just a bucket: "ages 20–30", "ages 30–40", and so on.

PICTURE. Two bar charts, same bins, side by side. The heights are fractions (each chart sums to ) so pile sizes don't matter — only shape.

Figure — Model retraining pipelines

Step 2 — What "drift" looks like, bin by bin

WHAT. For each bin, look at the gap : how much more (or less) of production sits in this bin compared to training.

WHY. If nothing drifted, both charts have the same shape, so every gap is . A non-zero gap in any bin is the raw fingerprint of change. This subtraction is our first candidate ingredient.

PICTURE. The two charts overlaid; a coloured arrow in each bin shows the gap. Some arrows point up (, production over-represented), some down (, under-represented).

Figure — Model retraining pipelines


Step 3 — Killing the cancellation with a ratio

WHAT. Instead of asking "how big is the gap?", ask "how many times bigger is production than training in this bin?" — the ratio .

WHY. A ratio is scale-aware. Going from to is a blow-up (a big relative deal, possibly a new customer segment) even though the gap looks tiny. Absolute gaps miss this; ratios catch it. This is why drift measures speak in ratios, not differences alone.

PICTURE. For one bin, two stacked bars whose ratio is highlighted: means "twice as tall".

Figure — Model retraining pipelines

Step 4 — Why we wrap the ratio in a logarithm

WHAT. We don't use the ratio raw — we take its natural log, .

WHY — this is the key tool choice. A bare ratio is lopsided. "Doubling" is ; "halving" is . These are equally severe drifts, but is unit above the no-change point while is only below it — the raw ratio punishes growth more than shrinkage. The logarithm is exactly the tool that fixes this, because turns "multiply" into "add" and turns reciprocals into sign-flips: So doubling gives and halving gives equal magnitude, opposite sign. That symmetry is what a fair drift score needs, and no other simple function delivers it. (This is the same logic behind KL divergence, which also lives on of a ratio.)

PICTURE. The curve through the point : flat-crossing at the no-change ratio, symmetric in the log sense about it, negative left of , positive right of .

Figure — Model retraining pipelines

Step 5 — The sign-matching miracle: why every term is

WHAT. Multiply the two ingredients we built: the signed gap from Step 2 and the log-ratio from Step 4. This product is the per-bin PSI term.

WHY. Look at the signs together. Both ingredients read the same comparison ( vs ), so they always agree in sign — and a product of two same-sign numbers is never negative:

PICTURE. A sign table drawn as two coloured regions. Left region: (both factors negative → product positive). Right region: (both factors positive → product positive). The middle line gives exactly .

Figure — Model retraining pipelines


Step 6 — Summing the bins into ONE drift number

WHAT. Add every bin's term. That sum is the Population Stability Index.

WHY. Each term is a local drift measurement; total drift of the whole feature is their sum. Because each piece is , nothing cancels — a big shift anywhere survives into the total.

PICTURE. The per-bin terms drawn as a small ascending stack that accumulates into one bar labelled PSI, next to the traffic-light thresholds.

Figure — Model retraining pipelines

Step 7 — Degenerate cases we must not ignore

WHAT. What happens at the edges: an empty bin, and the perfect-match bin.

WHY. The contract says cover every case. If some bin has (training never saw this range) but (production does), then divides by zero → . The term explodes. Likewise gives , but the gap is negative, so the product still blows up positively.

PICTURE. A bin with a zero training bar and a tall production bar; a warning label showing the term shooting to infinity, and the standard fix (a tiny floor added to empty bins).

Figure — Model retraining pipelines

Step 8 — Watching the numbers walk (worked, term by term)

WHAT. Recompute the parent note's Example 1 so you can see each term land as a bar.

WHY. A worked walk anchors the abstract sum to real arithmetic and confirms the property visually — no term dips below the axis.

Expected , Actual :

Bin term
1
2
3

PICTURE. Three positive bars (one from a negative gap, two from positive gaps) all above the axis, summing to the PSI marker below the green line.

Figure — Model retraining pipelines

The one-picture summary

The whole derivation in a single frame: two histograms → per-bin gap and log-ratio → same-sign product → sum → PSI → traffic light → retrain trigger.

Figure — Model retraining pipelines
Recall Feynman: retell the whole walkthrough to a friend

We had two piles of the same measurement — old (training) and new (live). We turned each pile into a little bar chart of fractions. For each bar we asked two things: "how big is the gap?" () and "how many times did it grow or shrink?" (). Adding raw gaps was useless — pluses and minuses cancel to zero. So we took the log of the ratio, because log makes "double" and "halve" equally sized but opposite in sign, and it's exactly when nothing changed. The magic: the gap and the log-ratio always point the same way, so their product is never negative. Add all those non-negative pieces and you get one number, PSI. Zero means the world hasn't moved; big means it has. We floor empty bins so nothing blows up. Then a traffic light: green ignore, amber watch, red — wake the retraining robot.

Recall Quick self-test

Why can't a plain sum of gaps detect drift? ::: Because always — pluses and minuses cancel. Why the logarithm and not the raw ratio? ::: makes doubling and halving equal-magnitude, opposite-sign, and is exactly at ratio . Why is every PSI term ? ::: The gap and the log-ratio always share a sign, and same-sign product is non-negative. What breaks the formula and how do we fix it? ::: An empty bin () makes the log-ratio infinite; floor fractions with a tiny or merge bins. Does PSI measure accuracy? ::: No — only input drift; confirm with real performance before retraining.

Related: Data drift and concept drift · KL divergence · Model monitoring and observability · CI-CD for ML (CI-CD-CT) · Champion-Challenger and A-B testing · Feature stores · Data versioning and lineage · Shadow deployment and canary release