Sub topic 3
Framing the Problem and Choosing Success Metrics
This chapter assumes you can train and evaluate a supervised model in Python, know terms such as precision, recall and accuracy, and have a general idea of how a web service is deployed. It covers the first lifecycle stage, problem framing. The decisions made here set what the data, evaluation, release and monitoring stages later measure.
Why framing is an operations concern
Problem framing is the step where a business need becomes a machine learning task with a measurable definition of success. Teams often skip it and start with a model. The result is a system that scores well on a notebook metric and does nothing for the business.
Framing matters to MLOps because every later stage refers back to it:
- Data management uses it to decide which records and labels to collect.
- Evaluation uses it to set release criteria.
- Monitoring uses it to decide which signals show a failing model.
- Retraining uses it to decide when a model is no longer good enough.
If the success definition is vague, none of these stages can be automated. A pipeline cannot check "the model is useful". It can check "recall on fraud cases is at least 0.80 on the latest holdout set".
Step 1: Decide whether ML is the right tool
Ask these questions before choosing a model type.
- Could a rule, a lookup table or a SQL query solve the problem well enough? If so, use that. It is cheaper to run and easier to explain.
- Is there a pattern in historical data that predicts the outcome?
- Will the same kind of data be available at prediction time?
- Is the cost of a wrong prediction acceptable, or is there a fallback, such as a human reviewer?
- Will the system be used often enough to justify the cost of operating it?
A model needs data pipelines, monitoring and retraining for its whole life. Treat that cost as part of the decision.
Step 2: Translate the business goal into an ML task
A business goal says what the organization wants. An ML task says what the model predicts. The two are linked but not the same.
| Business goal | Possible ML task | Prediction target |
|---|---|---|
| Reduce customer churn | Binary classification | Will this customer cancel within 30 days? |
| Reduce fraud losses | Binary classification, ranked by risk | Is this transaction fraudulent? |
| Cut warehouse stock-outs | Regression or forecasting | Units demanded next week per product |
| Route support tickets faster | Multiclass classification | Which team should handle this ticket? |
The same goal can be framed in more than one way, and the framing changes the data and the metrics. "Reduce churn" can be a classification (will they leave?), a regression (how many days until they leave?) or a ranking (which customers should the retention team call first?). Pick the framing that matches the decision someone will take with the prediction.
Define the prediction point and the label
Two details cause many production failures:
- Prediction point. The moment at which the model must produce a prediction. A churn model that runs at the start of each month may only use data available on that day.
- Label definition. The exact rule that turns history into a target. "Churned" might mean "cancelled within 30 days", "stopped logging in for 60 days" or "did not renew". Each rule gives a different dataset.
If features include information that is only known after the prediction point, you have label leakage (also called target leakage). The model looks excellent offline and fails in production. Writing the prediction point down early gives you a rule to check every feature against.
Step 3: Choose metrics at three levels
A project needs more than one kind of metric. Each kind answers a different question.
| Level | Question | Example |
|---|---|---|
| Business metric | Did the outcome improve? | Retained revenue, fraud losses avoided |
| Model metric | How well does the model predict on held-out data? | Recall, precision, F1, AUC, RMSE |
| Operational metric | Does the system run well enough? | p95 latency, cost per 1,000 predictions, error rate |
Model metrics are what you can compute during training, so they feed experiment tracking and release gates. Business metrics are what you actually care about, but they arrive late and are affected by many other factors. Operational metrics decide whether the model can be served at all.
Step 4: Pick model metrics that fit the cost of errors
Accuracy is the share of predictions that are correct. It is easy to compute and often misleading.
Suppose 1 transaction in 100 is fraudulent. A model that always predicts "not fraud" reaches 99% accuracy and catches no fraud. The metric has to reflect which mistakes are expensive.
- Precision is the share of positive predictions that are correct. Prefer it when false alarms are costly, for example when every flagged transaction triggers a manual review.
- Recall is the share of actual positives the model finds. Prefer it when misses are costly, for example in screening for a serious disease.
- F1 combines precision and recall into one number. It treats the two as equally important, which is rarely exactly true.
- AUC (area under the ROC curve) measures how well the model ranks positives above negatives across all thresholds. It does not depend on a single threshold, but it can look fine on heavily imbalanced data when the precision at useful thresholds is poor.
- RMSE and MAE measure regression error. RMSE penalizes large errors more than MAE does.
The following code shows why accuracy alone fails on imbalanced data.
import numpy as np
from sklearn.metrics import accuracy_score, precision_score, recall_score
rng = np.random.default_rng(0)
y_true = (rng.random(10_000) < 0.01).astype(int) # about 1% positives
y_always_negative = np.zeros_like(y_true)
print("accuracy:", accuracy_score(y_true, y_always_negative))
print("recall:", recall_score(y_true, y_always_negative))
print(
"precision:",
precision_score(y_true, y_always_negative, zero_division=0),
)The accuracy is about 0.99, while recall is 0.0. A release gate based on accuracy would pass this model.
Turn error costs into a threshold
Many classifiers output a score, and a threshold converts it into a decision. The threshold is a product decision, not just a technical default of 0.5. If a missed fraud case costs 200 and a false alarm costs 5, the best threshold is much lower than 0.5. Choose the threshold on validation data using these costs, and store it as a versioned configuration value. A model and its threshold are released together.
Step 5: Set targets, baselines and guardrails
A metric without a target cannot gate a release. For each metric, write down three things.
- Baseline. The performance of the simplest alternative: the current rule, the current production model, or a trivial predictor such as the majority class. A model must beat the baseline to justify its cost.
- Target. The value at which the model is useful, ideally derived from the business case.
- Guardrail. A metric that must not get worse while you improve the main one. For example, you may improve recall as long as p95 latency stays below 100 ms and precision stays above 0.30.
Write these as a short, versioned document or config file in the repository. The automated release criteria in the evaluation and CI/CD chapters read from it.
from dataclasses import dataclass
@dataclass(frozen=True)
class SuccessCriteria:
primary_metric: str = "recall"
primary_target: float = 0.80
min_precision: float = 0.30
max_p95_latency_ms: float = 100.0
decision_threshold: float = 0.20
def met(self, recall, precision, p95_latency_ms):
return (
recall >= self.primary_target
and precision >= self.min_precision
and p95_latency_ms <= self.max_p95_latency_ms
)
criteria = SuccessCriteria()
print(criteria.met(recall=0.83, precision=0.35, p95_latency_ms=80)) # True
print(criteria.met(recall=0.85, precision=0.20, p95_latency_ms=80)) # FalseCommon errors
- Optimizing a proxy that drifts from the goal. Click-through rate can rise while user satisfaction falls. Check periodically that the model metric still relates to the business metric.
- Evaluating on data that does not match production. A random split can mix time periods. If the model predicts the future, split by time so the test set comes after the training set.
- Ignoring label delay. In fraud or churn, the true label may arrive weeks after the prediction. Monitoring must then rely on proxy signals until labels arrive, which the monitoring chapter covers.
- Letting the threshold stay implicit. An unrecorded threshold makes two runs with the same model give different decisions.
- Choosing one metric only. A single number hides trade-offs. Pair a primary metric with guardrails.
- No baseline. Without one, a score of 0.88 means nothing.
What you carry forward
The framing record connects the remaining stages. Data validation checks that labels follow your definition. Feature work checks that every input exists at the prediction point. Experiment tracking records the metrics you chose. Release criteria encode your targets and guardrails. Monitoring watches both the model metrics and the business metrics, and retraining triggers refer to the same thresholds.
Exercise
A team builds a model to flag fraudulent card payments. About 0.5% of payments are fraud. A manual reviewer checks every flagged payment, and reviewers can handle only a limited number per day. The team proposes "accuracy above 99%" as the release criterion. Explain why this is a poor criterion, and propose a primary metric, one guardrail, and the information the team needs to set the decision threshold.
Show answer
Always predicting "not fraud" reaches about 99.5% accuracy while catching no fraud, so the criterion would pass a useless model. A better primary metric is recall on fraud cases (or recall at a fixed precision), because missed fraud causes the losses. A guardrail is a minimum precision, or a cap on the number of flags per day, because reviewers have limited capacity and every false alarm costs review time. To set the threshold, the team needs the cost of a missed fraud case, the cost of a false alarm, and the daily review capacity. They choose the threshold on validation data that minimizes expected cost within the capacity limit, then version it with the model. They should also record a baseline, such as the current rule-based system, and split data by time so the evaluation matches production.
Exercise
A churn model is trained using a feature "number of support calls in the 30 days after the month start". The model has very high AUC offline but performs poorly in production. What is the likely cause, and how would a written prediction point have prevented it?
Show answer
The feature uses data from after the prediction point, because the model runs at the start of the month and cannot know about calls in the following 30 days. This is label (target) leakage: the feature is correlated with the outcome partly because it is observed after or alongside it. Offline evaluation sees the future data, so the score is inflated, while production lacks it. A written prediction point ("the model runs on day 1 of the month using only data up to that day") gives a rule to check each feature against, so the feature would have been rejected during feature review.