ML in Production (method view)
P5.ml-methods.07 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Model Evaluation, Selection & Interpretability
Where next?
Go up a level
P5.ml-methods.07 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Model Evaluation, Selection & Interpretability
Go up a level
A model that passed every offline check can rot in production without a single line of code changing, because the world it scores keeps moving while the model stands still. This module takes the five failures behind that sentence one at a time — the inputs drift away from the training distribution, the training and serving pipelines quietly compute the same feature differently, the proxy metric being optimised detaches from the business outcome it stood for, statistical rigour erodes under the pressure to find effects, and a recommender meets users and items it has never seen. Everything builds on the offline evaluation discipline of the previous module, and each failure is made concrete enough, in numbers or a few lines of code, to reconstruct in a data-scientist interview.
Framing. In production the model is the easy part — the data moves, the offline/online paths diverge, and the proxy metric gets gamed. Each step turns one production failure into numbers.
Read this module for the concepts and the interview framing; head to the P13 pillar (Production ML & MLOps) when you want to build the infrastructure — deployment pipelines, feature stores, eval harnesses, and monitoring dashboards — around them.
Why it matters — This module is the method-level view of production concerns: what drift, skew, and Goodhart failures are and how to reason about them in an interview. The Production ML & MLOps pillar (P13) goes deep on the same topics with hands-on case studies — packaging a model, serving it, and wiring up drift monitoring — and its modules reference this one rather than re-teaching it.
1 — Monitoring: data drift, concept drift, feedback loops (s35). Data drift = the input shifts while holds; concept drift = the relationship itself changes (the dangerous one — only delayed-label performance catches it). Watch inputs with the population stability index (PSI) or KS test; watch the relationship with performance on labels as they arrive.
Worked example — a PSI alert on an input feature. Compare a feature's live distribution against the training reference by bucket:
PSI = sum( (live% - ref%) * ln(live% / ref%) ) over buckets
rule of thumb: < 0.10 no shift
0.10-0.25 moderate shift -> investigate
> 0.25 major shift -> retrain
measured PSI = 0.25 -> major drift, trigger a retrainA PSI of 0.25 trips the major-shift threshold, so the input distribution has moved far enough to retrain. But PSI only sees inputs — if fraud tactics evolve (concept drift) with unchanged, PSI stays quiet and only delayed-label AUC reveals it. Beware feedback loops too: a recommender that only shows popular items starves the tail, and future training data confirms the bias.
Note. Monitoring is the online half of a loop whose offline half is the eval harness: drift here is the trigger to refresh the eval set and re-run evaluation before retraining. The evaluation infrastructure for that loop — eval harnesses and experiment tracking — lives in the P13 pillar, Production ML & MLOps.
Interview-depth production ML for the data-scientist track: drift monitoring and feedback loops, the MLOps stack and training-serving skew, aligning metrics with business impact, statistical-rigour failures, and recommenders — with the assumptions and the 'why' framing. Back to the foundations: ML6 — Evaluation & Model Selection, and Advanced Probability.
Once a model is live the world moves underneath it. Distinguish the failure modes:
concept drift demands
label-based performance monitoring.Detection. For inputs, compare live vs reference distributions with the population stability index (PSI), KS test, or per-feature histograms/embeddings. For the relationship, track performance on delayed labels (AUC, error) as ground truth arrives — the only direct signal for concept drift.
Feedback loops. Beware when the model's own actions change future data: a recommender that only shows popular items starves the tail of impressions, so future training data confirms the bias (a self-fulfilling loop). Left unmonitored these degrade silently and entrench bias.
Respond with alerting thresholds on drift metrics, scheduled or trigger-based retraining, shadow evaluation before promotion, and logging exploration to break feedback loops.
MLOps is DevOps adapted to the fact that an ML system is code + data + model, all three of which drift. It covers:
feature store — a central, versioned place to define and serve
features, giving the same transform to training (offline/batch) and
serving (online) code.Training-serving skew. The classic silent killer: training-serving skew
is any difference between how features are computed offline for training
vs online for serving — a subtly different transform, a unit mismatch, or
stale features (training on fresh data, serving on an hours-old cache).
Metrics look fine offline yet production accuracy quietly degrades because
the model sees inputs it was never trained on. The structural fix is a shared
feature store or a single library of feature transforms invoked
identically in both paths, so offline and online computations are provably
the same.
A model metric is only ever a proxy for the value the business actually wants. Optimising AUC, log-loss, or click-through rate is a stand-in for revenue, retention, or user well-being — and the two can diverge sharply.
Goodhart's law — "when a measure becomes a target, it ceases to be a good measure." The moment you optimise a proxy hard, the system finds ways to raise the number without delivering the underlying value: a CTR-maximising feed learns clickbait; a "time-on-site" target breeds addictive dark patterns. Goodhart is the reason a metric that correlated with value in observation stops correlating once it is the optimisation target.
Defences:
Running experiments analytically honestly is harder than it looks.
p-hacking — trying many analyses, subgroups, or stopping rules and
reporting only the ones that cross p < 0.05. The garden of forking
paths captures the subtler version: even without conscious cheating,
data-dependent choices at each fork inflate the false-positive rate far
above the nominal α.Defences:
Three families of recommender:
The cold-start problem. A pure collaborative system is helpless when
there is no interaction history — a brand-new user or a just-added item
has no rows/columns to factorise. Mitigations:
Practical references for production ML and MLOps.
| Type | Resource |
|---|---|
| Book | Huyen, Designing Machine Learning Systems — drift, feature stores, deploy |
| Book | Kleppmann, Designing Data-Intensive Applications — data pipelines |
| Paper | Sculley et al., Hidden Technical Debt in Machine Learning Systems |
| In-app | ML4 — Causal Inference (P5.ml-methods.04), for the online experiments that validate these metrics |
| In-app | ML6 — Evaluation & Model Selection (P5.ml-methods.06), for the offline metrics these systems monitor |
| In-app | P13 — Production ML & MLOps pillar, for the case-study deep dives (packaging, serving, drift monitoring) |
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.
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...