5.3.12 · D4MLOps & Deployment

Exercises — Model monitoring and observability

2,601 words12 min readBack to topic

Before we start, three quantities recur everywhere, so pin them down in plain words:

Figure — Model monitoring and observability

Level 1 — Recognition

Recall Solution L1.1

The inputs look the same, but the mapping from inputs to the correct label changed: the same features now map to a different truth. That is a change in = concept drift. Why this and not data drift? Data drift is moving — the features themselves shifting. Here the features are unchanged; only the input→output relationship moved. See Data drift and concept drift.

Recall Solution L1.2

, which is the moderate band. Verdict: moderate shift — investigate, do not panic-retrain yet. The bands are: stable, moderate, major.

Recall Solution L1.3

First = monitoring (a known metric against a known threshold — is it broken?). Second = observability (asking a new question of the logged data without shipping code — why is it broken?). See Logging, metrics and tracing.


Level 2 — Application

Recall Solution L2.1

Term by term, each is :

  • Bin 1: .
  • Bin 2: .
  • Bin 3: .

Sum . Why every term is positive: a bin that shrank has both factors negative (product positive); a bin that grew has both positive. Deviations can only add. Verdict: is in moderate.

Recall Solution L2.2

Each sample has 4 points, so each point contributes to its CDF. Evaluate the gap at every point where either CDF steps up (the sup of a step-function gap always lands at a data point):

gap
2 0.25 0.00 0.25
4 0.50 0.00 0.50
5 0.50 0.25 0.25
6 0.75 0.50 0.25
7 0.75 0.75 0.00
8 1.00 1.00 0.00

The largest gap is at : . Why check only step points: between two data points both CDFs are flat, so the gap cannot grow there — the maximum must occur where one curve jumps. See figure below.

Figure — Model monitoring and observability
Recall Solution L2.3

. It exactly meets 0.85, so it is on the boundary — not failing, but with zero margin it deserves a closer watch.


Level 3 — Analysis

Recall Solution L3.1
  • Feature A (continuous): KS statistic is natural — it compares the full empirical CDFs, and CDFs are defined for continuous, ordered values. PSI also works if you bin A, but binning throws away resolution.
  • Feature B (categorical, 6 levels): PSI fits cleanly — the 6 categories are the bins, no ordering needed. KS needs an ordering to define a CDF, so it is awkward for unordered categories.
  • Neither replaces performance tracking once labels arrive — drift tests are input-side proxies, not proof of harm. See KL divergence and cross-entropy for why PSI is a symmetrised relative-entropy cousin.
Recall Solution L3.2

First case: in every bin, so every and every . Product is 0 in both bins → exactly. That is the only time PSI is 0. Second case: bins now differ, both terms become nonzero-positive products, so — it rises from 0. Concretely .

Recall Solution L3.3

moved a lot (high PSI) but the model's accuracy held — strong evidence that is unchanged. This is harmless covariate shift: the input distribution shifted into a region the model still handles correctly. Do not retrain on the drift alone — accuracy is the ground truth and it is fine. Log the shift, keep watching in case labels later degrade. Retraining would spend effort (and risk) for no measured gain. See Model retraining and CI-CD pipelines.


Level 4 — Synthesis

Recall Solution L4.1

Chain the clues. The global accuracy drop is real (b confirms it is concentrated, not spread). High PSI on income (a) is explained entirely by (c): a pipeline change made income null for DE, which both (i) makes the distribution look wildly shifted and (ii) breaks predictions for exactly those rows. Root cause = data quality / pipeline bug, not concept drift. Prescription: roll back or fix the pipeline so income populates again; do not retrain — training on null-poisoned data would bake the bug in. This mirrors the parent note's observability example. See Logging, metrics and tracing.

Recall Solution L4.2

Layered proxies, fastest first:

  1. Operational (seconds): latency, error rate, null-rate on features — catches pipeline breakage. Proves system health, not model correctness.
  2. Input drift (daily): PSI / KS on each feature vs reference — catches shifts. Proves inputs moved, not that predictions are wrong.
  3. Prediction drift (daily): PSI on (e.g. default-rate the model predicts) — catches output shifts. Suggests something changed; cannot separate input-driven from concept drift.
  4. Delayed performance (as labels trickle in): sliding-window accuracy on the 9-month-matured cohort — the only signal that proves real degradation, but arrives late. Rationale: layers 1–3 are cheap early warnings because ground truth (layer 4) is delayed and expensive. Consider A-B testing and shadow deployment to validate a candidate fix before full rollout.

Level 5 — Mastery

Recall Solution L5.1

(a) Each independent test raises a false alarm with probability . Expected false alarms per day . So 2 spurious "drift" alerts every single day, even in a perfectly stable system. (b) This is the multiple-comparisons problem: testing many features inflates the chance of some false positive. The probability of at least one false alarm is — about 87% every day. Fixes: (i) Bonferroni-style tighten to per test; (ii) require drift to persist across several windows before paging; (iii) alert on effect size (KS or PSI magnitude) rather than p-value alone. This keeps engineers trusting the alarms instead of muting them.

Recall Solution L5.2

Consider the two factors of a bin's term. The logarithm is positive when (ratio ), negative when (ratio ), and zero when . Crucially, carries the same sign in each case: positive when the bin grew, negative when it shrank, zero when equal. A product of two same-signed numbers is . Therefore every term is , and their sum PSI . PSI iff every term is 0, which requires in every bin — i.e. the two distributions are identical. Any single bin differing makes PSI strictly positive. (This is why PSI, like KL divergence, is a valid "distance-ish" score — see KL divergence and cross-entropy.)


Recall

Recall Active recall — cover the answers
  • PSI is exactly 0 when? ⇒ every bin matches: for all (identical distributions).
  • Where does the sup in the KS statistic always occur? ⇒ at a data point where one CDF steps up.
  • High input PSI but flat accuracy means? ⇒ harmless covariate shift — don't retrain on drift alone.
  • 40 features at each gives how many false alarms/day? ⇒ about 2 expected (~87% chance of ≥1).
  • Why layer proxies before performance? ⇒ ground truth is delayed/expensive; proxies warn early.

Connections

When is PSI exactly zero?
Only when the reference and new distributions are identical ( in every bin).
Where does the KS supremum gap occur?
At a data point where one of the empirical CDFs steps up (never strictly between points).
40 KS tests at alpha 0.05 — expected daily false alarms?
About 2 (); probability of at least one is .
High PSI but unchanged accuracy — retrain?
No — likely harmless covariate shift or a data bug; confirm a real performance drop first.