Sub topic 1
Why Models Fail After Deployment
A model that scored well on a held-out test set can still lose accuracy, return nonsense, or crash within weeks of going live. This chapter explains the main causes. It also shows how to tell a broken pipeline from a changed world, and it sets up the monitoring layers the next chapters build on.
Prerequisites
This chapter assumes you can:
- Read and write basic Python and NumPy.
- Train and evaluate a supervised model, and you know what a train/test split is.
- Read basic statistics: distributions, hypothesis tests and p-values.
- Describe how a model is served, either as a batch job or as an API.
You do not need any monitoring tools. The code uses only NumPy, SciPy and scikit-learn.
What offline evaluation actually promises
Offline evaluation estimates how a model performs on data drawn from the same distribution as the test set. That is a narrow promise. It holds only if three things stay true after deployment:
- Production inputs look like the training inputs.
- The relationship between inputs and the target stays the same.
- The code that builds features at serving time does what the training code did.
Production breaks each of these, and each break has its own symptoms and fix. Test-set accuracy says nothing about any of them, because the test set was frozen at one moment.
Three families of failure
Failures after deployment fall into three groups.
| Family | What changed | Typical example | Model code at fault? |
|---|---|---|---|
| Pipeline failure | The data feeding the model is broken | A upstream team renames a column, so the feature is always null | No |
| Data change | The inputs have a different distribution | A marketing campaign brings in younger customers | No |
| World change | The input-to-target relationship moved | Fraudsters adopt a new tactic | No, but the model is now wrong |
The distinction matters because the responses differ. A pipeline failure is fixed by repairing the pipeline. Retraining on broken data makes things worse. A real change in the world is fixed by retraining or redesigning the model.
Pipeline failures
Pipeline failures are the most common and the cheapest to fix, so check for them first. They happen outside the model.
- Schema changes. A column is renamed, dropped, or reordered. If features are passed by position, the model silently reads the wrong values.
- Unit or encoding changes. A price field moves from dollars to cents. A category code gains a new value the encoder has never seen.
- Missing values. An upstream join starts failing, and a feature becomes null for 40% of rows. Many pipelines fill nulls with a default, which hides the problem.
- Training-serving skew. The feature code used in training differs from the code used in serving. For example, training computes "average spend over 30 days" in a warehouse, while serving computes it from a cache with a different window.
- Stale data. A feature table stops updating, so the model keeps seeing last week's values.
These failures are dangerous because the model does not raise an error. It receives numbers, so it returns predictions. The predictions are simply wrong.
The following snippet shows how a unit change slips past a model unnoticed. A simple range check catches it.
import numpy as np
rng = np.random.default_rng(0)
# Training data: price in dollars
train_price = rng.uniform(5, 500, size=1000)
# After an upstream change, the same field arrives in cents
prod_price = rng.uniform(5, 500, size=1000) * 100
lo, hi = train_price.min(), train_price.max()
out_of_range = np.mean((prod_price < lo) | (prod_price > hi))
print(f"Share of production values outside the training range: {out_of_range:.1%}")Roughly 99% of the production values fall outside the training range. A model would still produce a score for each one. Chapter material on data quality checks covers how to automate this.
Data change: the inputs move
Sometimes the pipeline is healthy and the data is correct, but the population has changed. This is called data drift (also called covariate shift when only the inputs change). Causes include:
- A new marketing channel, region or product line that brings in different users.
- Seasonality. A demand model trained on summer data sees winter.
- A change in a sensor, app version or logging behavior.
- Selection effects. The model's own decisions change who shows up. A loan model that rejects some applicants means you never see how they would have repaid.
The model is not wrong about the world it learned. It is being asked about regions of input space where it has little or no training data, so its predictions there are extrapolations.
The next chapters separate drift into covariate shift, label shift and concept drift. For now, keep one idea: the inputs differing from training is a property of the data and can be measured without labels.
World change: the relationship moves
The hardest case is concept drift. The inputs may look the same, but the correct answer for a given input has changed. Examples:
- After a regulation change, the same customer profile now has a different default risk.
- A recommender trained before a viral trend keeps ranking by old tastes.
- Spammers rewrite messages to avoid the phrases a filter learned.
You cannot detect concept drift from inputs alone, because the inputs are the same. You need labels, or a proxy for them, to see it. This is why performance monitoring and label delay get their own chapters.
Some concept drift is caused by the model itself. A fraud model that blocks a tactic pushes fraudsters to a new one. This feedback loop means the data a model sees is partly a response to the model.
Why you often cannot see the failure directly
Even when a model is failing, three things hide it.
- Labels arrive late or never. A credit model learns whether a loan defaulted months later. A churn model waits for the churn window to close. During that gap you are blind to accuracy.
- Failures are silent. A bad prediction returns HTTP 200. Service dashboards stay green.
- Aggregates hide segments. Overall accuracy can hold steady while one region or customer group degrades, because a large healthy group masks a small broken one.
For these reasons, you monitor several signals at once instead of waiting for accuracy to drop.
A small demonstration of silent degradation
This example trains a model, then evaluates it on data where the relationship has changed. Offline accuracy is high, and nothing in the serving code raises an error.
import numpy as np
from sklearn.linear_model import LogisticRegression
rng = np.random.default_rng(0)
def make_data(n, flip_feature_effect=False):
X = rng.normal(size=(n, 2))
signal = X[:, 0] + 0.5 * X[:, 1]
if flip_feature_effect:
signal = -X[:, 0] + 0.5 * X[:, 1] # relationship has changed
y = (signal + rng.normal(scale=0.5, size=n) > 0).astype(int)
return X, y
X_train, y_train = make_data(5000)
X_test, y_test = make_data(2000)
X_prod, y_prod = make_data(2000, flip_feature_effect=True)
model = LogisticRegression().fit(X_train, y_train)
print(f"Offline accuracy: {model.score(X_test, y_test):.3f}")
print(f"Production accuracy: {model.score(X_prod, y_prod):.3f}")
print(f"Input mean shift: {np.abs(X_prod.mean(axis=0) - X_train.mean(axis=0)).max():.3f}")The input means barely move, so a check on input distributions sees nothing. Accuracy drops sharply because the target relationship changed. This is concept drift, and only labels reveal it.
Mapping failures to monitoring layers
Each failure family shows up in a different place, which is why the next chapter splits monitoring into layers.
| Failure | Where it is visible first | Needs labels? |
|---|---|---|
| Pipeline failure | Data quality checks (schema, nulls, ranges) | No |
| Data change | Input distribution tests | No |
| Prediction shift | Score and output distributions | No |
| World change | Performance metrics | Yes |
| Service outage | Latency, error rate, throughput | No |
No single layer catches everything. Input checks miss concept drift. Performance metrics arrive too late for pipeline failures that need a fast response.
Common mistakes
- Assuming a green service means a healthy model. Operational metrics only show the service is running.
- Retraining as the first reaction. If the cause is a broken pipeline, a retrain fits the model to corrupted data.
- Treating all drift as harmful. Inputs can change without hurting predictions. A later chapter covers when drift matters.
- Monitoring only the global average. Slice by segment to find localized failures.
- Not logging inputs and predictions. Without a record of what the model saw and returned, you cannot diagnose anything afterward.
Summary
Models fail in production for three reasons: the pipeline breaks, the inputs change, or the world changes. Offline evaluation covers none of them. Most failures are silent, labels are often delayed, and averages can hide broken segments. The remaining chapters build a layered monitoring system that targets each cause, starting with what to track.
Exercise
A fraud model's test AUC was 0.94. Three weeks after launch, a dashboard shows normal latency and error rate, the input feature distributions match training, but the fraud team reports many missed cases. Which failure family is most likely, and why can input distribution checks not catch it?
Show answer
Most likely concept drift (world change). Fraudsters changed tactics, so the same kinds of inputs now map to different correct answers. Input distribution checks compare only feature values, and those still look like training data. Only labels, such as confirmed fraud cases, or proxy signals reveal the drop in performance.
Exercise
A feature that was in dollars during training starts arriving in cents. The model keeps returning scores with no errors. Name two cheap checks that would catch this and say which failure family it belongs to.
Show answer
It is a pipeline failure. A range check against the training min and max, and a comparison of the feature's mean or quantiles against the training values, would both flag the roughly 100x change. A schema or unit validation at ingestion would also catch it.