Sub topic 8
Evaluating Models and Setting Release Criteria
Assume you know how to train a supervised model, split data into training and test sets, and calculate basic metrics. This chapter focuses on the decision after evaluation: whether a candidate model is safe and useful enough to release.
Evaluation is more than one score
A model evaluation compares a candidate model with a fixed reference. The reference might be the current production model, a simple baseline, or a business rule.
Use data that the model did not use during training. A holdout set is data kept separate for this final check. If information from the holdout set influences training or feature choices, the evaluation can become overly optimistic. This mistake is called data leakage.
Choose metrics that represent the real cost of errors:
- Accuracy is the fraction of predictions that are correct.
- Precision is the fraction of positive predictions that are correct.
- Recall is the fraction of actual positive cases that the model finds.
- Mean absolute error is the average absolute difference between predicted and actual numeric values.
- Latency is the time needed to produce a prediction.
A model can improve accuracy while becoming worse for an important user group. Evaluate useful slices, such as region, device type, or customer segment. Also check operational limits, such as memory use and response time.
Turn evaluation into a release decision
A release criterion is a rule that converts evaluation results into an approval or rejection. Good criteria include both an absolute requirement and a comparison with the current system.
For example, a candidate might need to:
- Reach at least 0.90 accuracy on an untouched test set.
- Match or exceed the production model's accuracy.
- Stay within the service's latency limit.
- Avoid a fairness or safety threshold violation.
- Pass reproducibility and data-quality checks.
Record the test data version, model version, metric values, and evaluation code. Otherwise, a later comparison may use different conditions.
Automate the gate
A continuous integration and continuous delivery (CI/CD) pipeline can run the same release rule for every candidate. The gate below requires an absolute floor and prevents a regression against production.
def should_promote(candidate_accuracy, production_accuracy,
min_gain=0.0, floor=0.90):
"""Return whether a candidate meets the release criteria."""
if candidate_accuracy < floor:
return False
return candidate_accuracy >= production_accuracy + min_gain
print(should_promote(0.94, 0.92)) # True
print(should_promote(0.89, 0.85)) # False: below the floor
print(should_promote(0.93, 0.95)) # False: worse than productionCommon evaluation errors
A single random split may hide rare cases. Use cross-validation during development, then keep a final untouched test set for the release decision. Do not repeatedly tune against that final set.
Do not compare metrics computed on different populations. A production score from last month is not directly comparable with a test score from a different season. Define the evaluation dataset and time range as part of the release record.
A threshold should also have an owner. When a candidate fails, the team needs to know whether to improve the model, inspect the data, or accept the trade-off.
Exercise
A candidate has 0.96 accuracy, while production has 0.94. However, its recall for a critical customer group is below the required minimum. Should it be released?
Show answer
No. The candidate must pass every mandatory criterion, including the group-specific recall threshold. Investigate or revise the model before release.