Sub topic 2
What to monitor: operational, data, prediction and performance layers
This chapter assumes you can train and evaluate a supervised model, read basic Python, and have deployed a model as a batch job or an API. It gives you a working model for what to watch in production. Later chapters cover each layer's tests in detail.
Why one dashboard is not enough
A model can fail in ways that no single metric shows. The service can be up while the inputs are broken. The inputs can look fine while the world has changed and accuracy has dropped. Splitting monitoring into layers lets you ask a different question at each level and find the failure faster.
The four layers run from cheap and immediate to costly and slow:
| Layer | Question it answers | Example signals | Needs labels? |
|---|---|---|---|
| Operational | Is the service running? | Latency, error rate, throughput | No |
| Data | Are the inputs valid and similar to training data? | Schema, missing values, ranges, drift scores | No |
| Prediction | Are the outputs behaving as usual? | Score distribution, predicted class rates | No |
| Performance | Are the predictions correct? | Accuracy, precision, recall, AUC | Yes |
Operational layer
This layer treats the model as any other service. Track latency percentiles (p50, p95, p99), error rates, and throughput. A sudden drop in throughput can mean an upstream system stopped sending data, which is also a model problem. These signals need no model knowledge and usually come from your existing observability stack.
Data layer
This layer checks the features entering the model. There are two kinds of check:
- Validity checks catch broken inputs: wrong types, missing columns, unexpected null rates, and values outside allowed ranges.
- Drift checks compare the current feature distributions against a reference window, such as the training data.
Validity checks are rule-based and should fail loudly. Drift checks are statistical and need thresholds, which is why they come later in this tutorial.
Prediction layer
Prediction monitoring watches what the model outputs. Track the distribution of scores, the share of each predicted class, and the rate of low-confidence predictions. If a fraud model that flags 1% of transactions suddenly flags 8%, something changed, even before you know whether the flags were right. This works without labels, so it is available immediately.
Performance layer
Performance monitoring is the only layer that measures correctness directly. It compares predictions to ground truth, the true outcomes. The cost is delay. A loan default label may arrive months later, and some labels never arrive. Chapters ahead cover how to estimate performance when labels are late.
What to log
Every layer depends on what you record at inference time. Log at least these fields for each prediction:
- A request or entity ID, so labels can be joined later.
- A timestamp.
- The model version.
- The input features as the model received them, after preprocessing.
- The prediction and its score.
Here is a minimal logging record in Python:
import json
import time
import uuid
def log_prediction(features: dict, score: float, label: int, model_version: str) -> str:
record = {
"request_id": str(uuid.uuid4()),
"timestamp": time.time(),
"model_version": model_version,
"features": features,
"score": score,
"prediction": label,
}
line = json.dumps(record)
print(line) # in production, send to a log store or message queue
return line
log_prediction({"age": 41, "income": 52000.0}, score=0.83, label=1, model_version="v3")Common errors
- Monitoring only accuracy. Labels are late, so you learn about failures long after they start.
- Monitoring only drift. A drift alert does not tell you whether performance dropped.
- Not logging the model version. After a rollback you cannot separate old and new behavior.
- Logging raw inputs but not the preprocessed features. You then cannot reproduce what the model saw.
Exercise
Your model's latency and error rate look normal, and the null rate of every feature is unchanged. Yet the share of positive predictions rose from 2% to 9% overnight, and labels will not arrive for 30 days. Which layer raised the signal, and what should you check next?
Show answer
The prediction layer raised it. Check the data layer for drift in the features that most influence the score, and check whether the model version or an upstream feature definition changed. Because labels are 30 days away, you cannot confirm a performance drop yet, so investigate the inputs and the pipeline first.