Monitoring & drift
P13.operations.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Serving & scaling
Where next?
This module unlocks
Go up a level
P13.operations.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Serving & scaling
This module unlocks
Go up a level
A model that passed every offline gate still decays in production — not because the code changed, but because the world did. Monitoring is the discipline of noticing that the live inputs (and outputs) no longer look like the data the model was trained and evaluated on, and turning that observation into a decision. P5.ml-methods.07 named drift as step 1 of the production loop; this module makes it measurable: PSI, the two-sample KS test, and the decision policy that converts a drift score into no-shift / monitor / retrain.
"Drift" is not one thing. Production systems fail in distinct ways, and the fix differs for each — so the first job of a monitor is to name which distribution moved. Write the model as learning P(y | x) over inputs drawn from P(x).
P(x) changes while P(y | x) holds. A new hospital onboards, so the age mix of incoming requests shifts. The learned mapping is still correct; you are just seeing inputs the model saw rarely in training.P(y | x) itself changes. The same input now has a different correct answer: a fraud pattern that used to be benign is now malicious. This is the dangerous one — the model is now wrong, not just under-sampled.P(y) changes while P(x | y) holds. The base rate of the positive class moves (an outbreak triples disease prevalence), which miscalibrates any threshold tuned to the old prior.P(x)) as an early warning, and confirms with the lagging signal (measured accuracy) once labels land.This is the same measurement machinery as the offline eval harness in P13.ml-lifecycle.01, run at a different point in the lifecycle: the harness scores a candidate before ship; monitoring scores the live system after ship. A monitored drift is precisely the trigger to re-open the eval loop — refresh the eval set, re-run the gate, retrain. Offline and online are one loop, not two systems.
Practise this lesson's 3 self-checks
One per screen: you reveal each answer and mark it yourself. Nothing is recorded.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Build the drift detector yourself, bottom-up: the Population Stability Index from raw bins, a binning-free KS drift test on top of SciPy, and the worst-feature action policy that turns those scores into a no-shift / monitor / retrain decision. Local-first — the kernel has NumPy and SciPy but no live feature store, so you implement the detector; a real monitor wires it to a windowed stream.
Loading exercise…
Loading exercise…
Loading exercise…
P(x) moves, mapping still right) · concept (P(y|x) moves, model now wrong) · label/prior (P(y) moves, thresholds miscalibrated). Monitor inputs because labels lag or never arrive.Σ (a% − e%)·ln(a%/e%) over frozen reference bins. Bands: <0.1 stable · 0.1–0.2 moderate · ≥0.2 significant. Clamp fractions with an epsilon so empty bins don't blow up ln.D between empirical CDFs + a p-value; no binning. Power scales with n — a big D on tiny samples still gives a large p (worked example: D=0.4, p=0.87 at n=5+5).Where the pieces of this module lead.
| Type | Resource |
|---|---|
| In-app | P5.ml-methods.07 — Production ML & MLOps: drift is step 1 of the loop this module deepens |
| In-app | P13.ml-lifecycle.01 — Evaluation infrastructure: the offline half of the loop a retrain trigger re-opens |
| In-app | P13.operations.01 — the reliability/on-call foundations this monitoring plugs into |
| Docs | SciPy stats.ks_2samp; Evidently / NannyML drift monitors; the PSI credit-scoring literature |
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Loading your notes...