Sub topic 13
Deciding when a model is good enough
This chapter assumes you can build a baseline, pick a metric, and run repeated cross-validation in scikit-learn. You should also know what a standard error is. The earlier chapters covered those pieces. This one covers the decision they feed: ship the model, or keep working.
Good enough is a decision, not a score
A model score has no meaning until you compare it to something. "Balanced accuracy of 0.81" says nothing alone. It becomes useful when you know the baseline scored 0.50, the requirement was 0.75, and a human reviewer reaches about 0.85.
"Good enough" means the model meets criteria that you wrote down before looking at results. The criteria answer four questions:
- Is the model better than the baseline by more than noise?
- Is the gain large enough to matter for the product?
- How far is the model from a plausible ceiling?
- Is the gain worth the added cost and complexity?
Inputs to the decision
Each input comes from an earlier step in the workflow.
| Input | Question it answers | Typical source |
|---|---|---|
| Baseline comparison | Does the model beat the floor? | Dummy model, heuristic, or existing system |
| Uncertainty | Is the gain larger than run-to-run noise? | Repeated cross-validation |
| Performance ceiling | How much room is left? | Human agreement, irreducible error estimate |
| Error analysis | Where does the model fail, and does it matter? | Slice evaluation, inspection of mistakes |
| Cost trade-offs | What does the gain cost to run and maintain? | Latency, compute, engineering time |
The first two inputs are statistical. The remaining three need judgment, and they are where most disagreements happen.
Write the criteria first
Set the thresholds before you run the candidate model. If you set them afterwards, you will tend to pick numbers the model already passes.
A useful criteria set has three parts:
- A minimum useful gain. The smallest improvement over the baseline that changes a decision or a business outcome. Derive it from the product requirement, not from the data. For example: "A fraud model must catch at least 5 more fraudulent cases per 100 than the current rules to justify the review workload."
- A floor for every important slice. For instance, recall must not fall below a stated value for any region or customer segment.
- Operational limits. Maximum latency, memory, and retraining cost.
Write these in a short document or a pull request description. Include the metric, the data split, and the date you set the criteria.
Applying the statistical criterion
The following script is self-contained. It builds a paired comparison between a baseline and a logistic regression on identical folds, then checks whether the gain, minus a rough noise allowance, exceeds the minimum useful gain.
import numpy as np
from sklearn.datasets import make_classification
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import RepeatedStratifiedKFold, cross_val_score
X, y = make_classification(n_samples=2000, weights=[0.95, 0.05], random_state=0)
cv = RepeatedStratifiedKFold(n_splits=5, n_repeats=3, random_state=0)
baseline_scores = cross_val_score(
DummyClassifier(strategy="prior"), X, y, cv=cv, scoring="balanced_accuracy"
)
model_scores = cross_val_score(
LogisticRegression(max_iter=1000), X, y, cv=cv, scoring="balanced_accuracy"
)
diff = model_scores - baseline_scores
mean_gain = diff.mean()
std_err = diff.std(ddof=1) / np.sqrt(len(diff))
min_useful_gain = 0.05 # set from the product requirement, not from the data
lower_bound = mean_gain - 2 * std_err
print("mean gain:", mean_gain)
print("rough lower bound:", lower_bound)
print("good enough on this criterion:", lower_bound > min_useful_gain)Three details matter here.
- Both models use the same
cvobject with a fixed seed, so each fold of the baseline is paired with the same fold of the candidate. Pairing removes the variation that comes from which rows landed in which fold. - The lower bound is
mean_gain - 2 * std_err. It asks whether the gain is still above the minimum even in a pessimistic case. - The standard error is optimistic. Folds in repeated cross-validation share training rows, so the 15 differences are not independent. Treat the bound as a rough guide. A clear pass or a clear fail is informative. A result near the threshold is not a decision.
Ceilings and remaining headroom
The statistical check says the model beats the baseline. It does not say whether more work is worthwhile. For that you need a ceiling.
Two common ceiling estimates:
- Human performance. Have two or more people label the same sample and measure how well they agree with each other and with the ground truth. If humans reach 0.85 and your model reaches 0.82, further modeling effort has limited headroom.
- Irreducible error. Some error cannot be removed with the available features. Duplicate feature vectors with different labels are a sign of it. A very noisy target is another.
The ceiling is itself an estimate. Human labelers may be worse than the model on some slices and better on others. Use it as a range, not a single number.
When the gap between model and ceiling is small, effort is better spent on data quality, monitoring, or the surrounding product. When the gap is large and error analysis points to a fixable cause, keep iterating.
Error analysis before the verdict
An average can hide a failure that the criteria forbid. Before declaring a model good enough, compute the metric per slice. Useful slices include:
- A category with a low sample count.
- A time period, especially the most recent one.
- A customer segment, region, or device type.
- Rows with missing values.
- Examples near the decision threshold.
Then read a sample of the model's mistakes by hand. Ask whether they are ones a user would tolerate. A forecast that is off by 3% on ordinary days and off by 40% on promotion days may have an acceptable average and an unacceptable failure mode.
Small slices produce noisy scores. A slice with 20 examples cannot support a tight threshold. Either collect more data for that slice or state the uncertainty in the criteria.
Cost and complexity
A gain that clears the statistical bar can still fail on cost. Compare the candidate with the baseline on every operational dimension:
- Inference latency and memory.
- Training time and how often retraining is needed.
- Number of features and pipelines that must stay available in production.
- How hard it is to explain a prediction to a user or auditor.
- Engineering time to maintain the system.
A simple way to frame it: express the gain in the unit the business cares about, such as cost saved per month or errors avoided per thousand predictions. Then compare with the added running cost. If you cannot express the gain in those terms, the minimum useful gain was probably not well defined.
Prefer the simpler model when the difference is small. A linear model that is 1% worse than a gradient-boosted ensemble but easier to monitor is often the better choice.
Decision flow
Edge cases and common errors
- Gain is real but below the minimum. The model is statistically better and still not good enough. Ship the baseline, or look for a different approach.
- Test set reused many times. If you tuned against the test set across many experiments, its score is optimistic. Hold out a fresh set for the final check.
- Metric mismatch. A model that passes on balanced accuracy may fail on the metric the product uses, such as recall at a fixed precision. Check the criteria metric, not a convenient one.
- Ceiling treated as a target. Reaching human level is not required when the product only needs a lower bar, and it is not sufficient when mistakes are costly.
- Baseline that is too weak. A gain over a majority-class predictor proves little. Compare with the strongest cheap baseline you have, such as the current system or a linear model.
- Noise near the threshold. If the lower bound is within a standard error of the minimum gain, run more repeats or collect more data before deciding.
Applying it in practice
- Write the metric, split, minimum useful gain, slice floors, and operational limits.
- Score the baselines and the candidate on identical repeated folds.
- Compute the paired gain and a rough lower bound.
- Compute per-slice scores and read a sample of errors.
- Compare with a ceiling estimate to decide whether iteration can pay off.
- Compare cost with gain. Pick the simpler model on a near tie.
- Record the decision and the baseline score for later comparison.
Exercise
A candidate model has a mean paired gain of 0.04 over the baseline on balanced accuracy, with a standard error of 0.005. The minimum useful gain, set before experiments, was 0.05. A teammate suggests lowering the minimum to 0.03 because "the model is clearly better than the baseline." Is the model good enough on this criterion, and how should you respond to the suggestion?
Show answer
No. The rough lower bound is 0.04 - 2 × 0.005 = 0.03, which is below 0.05, so the criterion fails. The gain is probably real, but it is smaller than the product requirement. Do not lower the threshold after seeing the result. If there is a genuine reason to revise the requirement, document the reason and the change, and treat the existing comparison as exploratory. Otherwise keep the baseline or iterate on the model.
Exercise
A model beats the baseline by more than the minimum useful gain, but its recall on one region with 25 test examples is far below the floor you set for that region. List two reasonable next steps.
Show answer
First, collect more labeled data for that region, because 25 examples give a very noisy slice score. Second, inspect that region's errors to find a cause, such as a missing feature or a labeling difference, and fix it. Do not ship on the overall average alone, because the criteria include a floor for every important slice.