MLOps: Models in the Real World

Shifting Sands

Robo's ice-cream model learned from summer days: warm and dry means kids buy ice cream. Now it is out in the real world, guessing for every kid who walks by. But the world keeps changing. Will Robo notice?

Press Play to start the stream of kids. Then use Change the world to bring a heat wave, a cold snap or a price rise, and watch my accuracy and the drift light.

Kid 0 of 2400

boughtdidn't buyanswer not here yetRobo was wrong (×)
accuracy you can seereal accuracy (found out later)robot that never retrainsworld changed

Top: each dot is one kid, placed by the temperature that day. The dashed line is Robo's rule: warmer than this and Robo guesses "buys". Bottom: how many of the last 200 guesses were right.

Challenges

Sound the alarm: change the world until the drift light turns red.
Sneaky drift: make the accuracy you can see sink below 60% while the drift light stays green.
False alarm: get the light red while Robo is still right more than 90% of the time.
Rescue: once accuracy drops below 60%, retrain and bring it back above 80%.
Smart keeper: finish a whole stream with the world changing, and beat the never-retrain robot by 10 points or more.

What just happened?

How it works

  1. Train a model once on summer days: temperature, weekend or not, rain or not. It learns a simple rule.
  2. Every new kid gets a guess right away. Their real answer (bought or not) shows up later.
  3. Drift check: sort temperatures into 10 buckets and compare how full each bucket is for training days and for the last 200 kids. Big differences add up to a big PSI.
  4. Accuracy check: of the last 200 kids whose answers have arrived, how many did Robo get right?
  5. If things look bad, retrain on the 300 most recent kids with answers. Those kids become the new "normal" for the drift check.
For grown-ups: what's really going on

A logistic regression on (standardised temperature, weekend, rain) is trained on 400 "summer" rows. True labels come from logit = 0.75·(min(T,31) − θ) − 1.6·max(0, T − 31) + 1.2·weekend − 2.2·rain with θ = 22°C, so the summer data never reveals the "too hot" downturn. The stream then serves one row per tick, generated with a seeded RNG.

  • Covariate shift changes P(x) but not P(y|x). Heat wave: T ~ N(36.5, 2.5) exposes the unseen part of P(y|x) (extrapolation failure). Cold snap: T ~ N(12, 4) is a big shift that barely hurts, because the model is right far from its boundary.
  • Concept drift changes P(y|x): "Price doubles" moves θ to 29°C. Feature monitors (PSI, KS) cannot see it; only labelled performance can, delayed by the label-delay slider. "Seasons" is a recurring shift (T mean ± 11°C, period 700 ticks). Sudden = a step; gradual = a 300-tick linear blend of all parameters.
  • PSI = Σk (ak − ek) ln(ak/ek) over 10 reference-quantile bins (two bins for the binary features), shares floored at 10⁻⁴. Rule of thumb: < 0.1 stable, 0.1–0.25 moderate, > 0.25 major. With finite samples PSI is biased upward: under no drift E[PSI] ≈ (B − 1)(1/n + 1/m), about 0.07 here, which is why the amber light needs PSI > 0.1 and a significant KS test.
  • Two-sample KS: D = supx |Fref(x) − Frecent(x)|, with the large-sample 5% critical value 1.358·√((n+m)/(nm)). With big windows KS flags tiny, harmless shifts; with small ones it misses real ones.
  • Retraining refits on the most recent 300 labelled rows and resets the drift reference to them. Accuracy-triggered retraining reacts to concept drift but lags by the label delay; PSI-triggered retraining reacts fast but fires on harmless shifts. Seasonal drift punishes a short sliding window: better to train on a full cycle or add season features.

Further reading: Gama et al. (2014), A Survey on Concept Drift Adaptation; Rabanser, Günnemann and Lipton (2019), Failing Loudly: An Empirical Study of Methods for Detecting Dataset Shift.