5.3.12MLOps & Deployment

Model monitoring and observability

1,894 words9 min readdifficulty · medium6 backlinks

WHY does a deployed model need monitoring?

WHAT can go wrong (the four failure families):

Failure What changes Example
Data drift (covariate shift) P(X)P(X) New age group of users signs up
Concept drift P(YX)P(Y\mid X) Same features, but "spam" definition changes
Label/prediction drift P(Y^)P(\hat{Y}) Model suddenly predicts "fraud" 5× more
System/operational latency, errors, throughput A feature pipeline returns nulls

HOW do we detect drift? (Derivation from first principles)

We can't see the true new distribution, only samples. So drift detection = a two-sample test: is the recent batch drawn from the same distribution as the training/reference batch?

1. Population Stability Index (PSI) — derive it

We want a single number for "how much did a distribution move?" Start with the idea of comparing two probability distributions bin-by-bin. Split the feature range into BB bins. Let eie_i = fraction in bin ii for the expected (reference) data, aia_i = fraction for actual (new) data.

A natural asymmetry-tolerant way to compare two probabilities is the difference weighted by the log-ratio (this is the symmetrised per-bin relative entropy):

PSI=i=1B(aiei)ln ⁣aiei\text{PSI} = \sum_{i=1}^{B} (a_i - e_i)\,\ln\!\frac{a_i}{e_i}

Rules of thumb: PSI <0.1<0.1 = stable; 0.10.10.250.25 = moderate shift, investigate; >0.25>0.25 = major shift, act.

2. Kolmogorov–Smirnov (KS) statistic

For continuous features, compare empirical CDFs:

D=supx  Fref(x)Fnew(x)D = \sup_x \; \big| F_{\text{ref}}(x) - F_{\text{new}}(x) \big|

WHY the sup of the CDF gap? The CDF captures the whole distribution shape; the largest vertical gap is the worst-case disagreement. A p-value from the KS test tells you if that gap is bigger than sampling noise.

3. When there are labels: track performance directly

If ground truth arrives (even delayed), the gold standard is just recomputing the metric on a sliding window:

Accuracyt=1Wt(x,y)Wt1[y^(x)=y]\text{Accuracy}_t = \frac{1}{|W_t|}\sum_{(x,y)\in W_t}\mathbf{1}[\hat{y}(x)=y]

Ground truth is often delayed (did the loan default? — wait months) or expensive (human labels). That's exactly why input/prediction drift are used as early proxies.

Figure — Model monitoring and observability

Worked Examples


Common Mistakes (Steel-manned)


Recall

Recall Active recall — cover the answers
  • What two-sample question underlies all drift detection? ⇒ Are recent samples from the same distribution as reference?
  • PSI is 0 exactly when…? ⇒ the two distributions are identical.
  • Monitoring vs observability in one line? ⇒ Monitoring = "is it broken?"; observability = "why?"
  • Why are input/prediction drift used as proxies? ⇒ Ground truth is delayed/expensive.
  • Data drift vs concept drift? ⇒ P(X)P(X) changes vs P(YX)P(Y\mid X) changes.
Recall Feynman: explain to a 12-year-old

Imagine you trained your dog to fetch a red ball. Now you go to a park where everyone throws blue balls. Your dog still runs, still looks happy — but keeps bringing back the wrong thing, and it never tells you it's confused. Model monitoring is like putting a little camera on the dog: you watch what balls are being thrown (inputs), what the dog brings back (predictions), and sometimes check if it's actually right (labels). If the balls turned blue, an alarm rings so you can re-train the dog before your whole game is ruined.


Connections

What is the difference between data drift and concept drift?
Data drift = change in input distribution P(X)P(X); concept drift = change in the input→output relationship P(YX)P(Y\mid X).
Define the Population Stability Index formula.
PSI=i(aiei)ln(ai/ei)\text{PSI}=\sum_i (a_i-e_i)\ln(a_i/e_i) over bins; 0 iff distributions identical.
What PSI value signals major drift?
PSI > 0.25 (0.1–0.25 = moderate, <0.1 = stable).
What does the KS statistic measure?
D=supxFref(x)Fnew(x)D=\sup_x|F_{ref}(x)-F_{new}(x)|, the largest gap between two empirical CDFs.
Monitoring vs observability?
Monitoring tracks known metrics ("is it broken?"); observability lets you ask arbitrary new questions from logs/metrics/traces ("why is it broken?").
Why use input/prediction drift as early warnings?
Because ground-truth labels are often delayed or expensive, so direct performance can't be measured in real time.
Why is a single global accuracy misleading?
It can hide a failing subgroup; slice metrics per segment/feature bin.
Give one reason drift does NOT always mean retrain.
The drift may be a broken data pipeline (nulls/wrong units) or a harmless covariate shift where P(YX)P(Y\mid X) is unchanged.
Why is PSI always non-negative?
Each term (aiei)ln(ai/ei)(a_i-e_i)\ln(a_i/e_i) has factors of the same sign, so the product is ≥0.

Concept Map

snapshot of past

causes

motivates

tracks known metrics

tracks

tracks

includes

includes

answers is it wrong

answers why wrong

detected via

implemented by

Deployed model

Monitoring

Observability

Drift in reality

Silent failure HTTP 200

Data drift P of X

Concept drift P of Y given X

Prediction drift

System health latency errors

Two-sample test

Population Stability Index

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, model deploy karne ke baad kaam khatam nahi hota — asli tension tab shuru hoti hai. Aapka model test set pe 95% laaya, matlab usne purane data ka pattern seekh liya. Lekin duniya badalti rehti hai: naye users aate hain, product change hota hai, data pipeline break ho jaati hai. Model crash nahi karta, bas chupchaap galat predictions deta rehta hai aur HTTP 200 bhejta rehta hai. Isi silent failure ko pakadne ke liye monitoring karte hain.

Do main cheezein yaad rakho. Data drift matlab input distribution P(X)P(X) badal gaya. Concept drift matlab input se output ka rishta P(YX)P(Y\mid X) hi badal gaya. Inko detect karne ka simple funda: do-sample test — kya naya batch usi distribution se aaya hai jaisa reference tha? Iske liye PSI ((aiei)ln(ai/ei)\sum (a_i-e_i)\ln(a_i/e_i), agar > 0.25 to bada drift) ya KS statistic (dono CDF ke beech ka sabse bada gap) use karte hain.

Ek important baat: monitoring bolta hai "kuch toota hai kya?", aur observability bolta hai "toota to kyun toota?". Jab accuracy giri, tab logs/traces se aap segment-wise slice karke root cause dhoondh sakte ho — jaise "sirf DE country ke users me income feature null aa raha hai". Isliye blindly retrain mat karo; pehle check karo — kya sach me performance giri, ya sirf pipeline bug hai. Yaad rakho PIPES — Performance, Inputs, Predictions, Errors/latency, Segments — sab clean rakho, tabhi production model bharosewala rahega.

Go deeper — visual, from zero

Test yourself — MLOps & Deployment

Connections