Vocabulary for this course

The terms the chapters assume, in plain words. You can open this from any chapter.

artefact
A saved file a release needs, such as the model, the code that prepares its inputs or the exact package versions.
batch
A run that scores many rows at once on a schedule and writes the results to a table.
canary
A release shown to a small random slice of traffic first, so a bad model reaches few users.
drift
A change in the inputs a model sees, or in the link between those inputs and the outcome it predicts.
evaluation gate
A check before release that stops a model when its measured quality falls below a set bar.
feature contract
An agreed promise about one input column — its type, range, missing values, uniqueness, freshness and owner — checked as data arrives.
incident
An event that degrades a service beyond its agreed level and needs a coordinated response.
inference contract
The agreed inputs, outputs and error cases for a model's prediction service, written down and tested.
latency budget
The time a request may spend in the model path, after network and rendering are subtracted from what users will tolerate.
model card
A short document describing what a model is for, how it was trained, its limits and who owns it.
monitoring
Watching inputs, outputs, service health and later outcomes so a change is noticed before users report it.
rollback
Returning to the last known good version, using a saved copy and a command that has been rehearsed.
serving
Running a model to answer requests in production, either one at a time or in scheduled groups.
training-serving skew
When an input is computed one way for model fitting and another way at request time, so the model reads different data.

MLOps from the ground up

Monitoring and drift

A model in production is a hypothesis under test. Monitor the inputs, the outputs, the service and the outcome, and know which one moved.

Part 4 of 10

Intermediate17 min readBack to Courses

Four layers

Service metrics cover latency, errors and saturation. Input metrics cover schema violations, missing fields and the distribution of each feature. Output metrics cover the score distribution and the prediction rate. Outcome metrics cover clicks, conversions and the labels that eventually arrive. Each layer answers a different question, and the first three are available immediately.

The layers fail in order. A schema change breaks the input, the input shifts the output, the output moves the outcome, and only then does the business metric fall. Watching the earliest layer is how you find the cause before the symptom reaches a dashboard someone checks weekly.

Dashboards and alerts are different products. A dashboard is for exploration during an incident; an alert is a decision that someone should stop what they are doing. Keep the dashboard rich and the alerts few, each with a runbook that says what to check first and what to do if the check fails.

Data drift and concept drift

Data drift is a change in the input distribution: a new device, a new country, a feature that stopped updating. Concept drift is a change in the relationship between inputs and the target: the same inputs now mean something different. The first is visible without labels; the second usually is not.

A pandemic, a price change or a competitor’s launch can all change what a click means. The model has not moved, but the world it was fitted to has. That is concept drift, and no amount of input monitoring will find it on its own.

Seasonality is the common false positive. Retail traffic changes every December, and a detector calibrated on November will call it drift. Compare the live window with the same window a year ago, or detrend the series before testing, or the alert will fire on the calendar rather than on the model.

A two-sample test with SciPy

from scipy.stats import ks_2samp

statistic, p_value = ks_2samp(reference_scores, live_scores)
print(f"KS={statistic:.3f} p={p_value:.4f}")
if p_value < 0.01:
    print("the distributions differ")

Population stability index

Run the report and find the bin that contributes most to the shift. Then move five users from the lowest bin to the highest in LIVE_COUNTS and see how the total changes.

Output
Click "Run" to execute your code

Detect with a statistic, not a hunch

Population stability index over binned values, a Kolmogorov–Smirnov test on a numeric feature, or a simple mean shift with a threshold. Each has assumptions; none is a substitute for looking at the plot. Alert on a sustained shift, not on a single window, or every quiet Sunday will page someone.

Choose the threshold from the cost of a false alarm and the cost of missing a real change. A feature that is cheap to recompute can tolerate a looser threshold than one that feeds a credit decision. The statistic is a tool; the threshold is a risk decision.

Univariate tests miss joint shifts. Two features can each look stable while their combination moves, because the correlation between them changed. A model’s own score distribution is a cheap multivariate check: if the inputs are stable and the scores are not, the interaction between features is the place to look.

Monitoring only the model’s outputs misses the input shift that caused them. A stable average score can hide two populations moving in opposite directions.

Labels arrive late

Accuracy may be unknown for days. Use proxies — the prediction distribution, downstream conversion, human review of a sample — and label the proxy as a proxy. When the labels land, reconcile the proxy with the truth and recalibrate the thresholds.

The reconciliation is the useful part. If the proxy said healthy and the labels say otherwise, the proxy is wrong and should be replaced or reweighted. A monitoring system that never checks itself becomes a source of false confidence.

Label delay is itself a signal. If the labels that normally arrive in a day take a week, the pipeline that produces them may be broken, and the model’s accuracy is unknown rather than unchanged. Monitor the label pipeline with the same seriousness as the prediction pipeline. A label pipeline that silently stops is worse than a wrong model, because the dashboard keeps showing the last good number and nobody knows it is stale.

A proxy that drifts from the truth

Run the report and find the first day where the mean score and the accuracy disagree. Then decide which signal you would page on and which you would only watch.

Output
Click "Run" to execute your code

Check what you learned

One question at a time. A wrong answer explains itself — take another go.

Part 1 of 5

Which monitoring layer is available first?