Sub topic 6
Choosing and Reporting Evaluation Data and Metrics
Prerequisites and scope
This chapter assumes you know the basics of supervised learning (training, validation, and test sets) and common metrics such as accuracy, precision, and recall. You should also be comfortable reading short Python snippets.
The evaluation section is the part of a model card that readers use to decide whether to trust a model. A number with no context misleads. "Accuracy: 0.91" says almost nothing until you know which data produced it, how the data was chosen, and what the metric rewards. This chapter covers how to pick evaluation data, how to pick metrics, and how to report both so a reader can judge the result. The next chapter splits these results by group and condition.
What the evaluation section must answer
A reader of the evaluation section should be able to answer five questions without contacting the authors:
- Which dataset was the model evaluated on, and which version of it?
- How does that dataset relate to the training data and to the data the model will see in use?
- Which metrics were computed, and with what decision threshold?
- How large is the uncertainty in each number?
- Can the result be reproduced?
If the section leaves any of these open, the numbers cannot be compared with another model's numbers or with your own results after retraining.
Choosing evaluation data
Hold-out data must be truly held out
The test set must not influence training, feature selection, or hyperparameter tuning. Tuning against the test set turns it into a second validation set, and the reported score becomes optimistic. Keep three roles separate:
- Training data fits the parameters.
- Validation data selects hyperparameters and decides when to stop.
- Test data is used once, for the reported result.
State in the card how the split was made. Common errors include random splits on data with repeated entities (the same customer, patient, or document appearing in both train and test), and random splits on time-ordered data. For data with repeated entities, split by entity. For time-ordered data, train on earlier records and test on later ones.
Leakage
Leakage is information in the evaluation data that the model would not have at prediction time, or that also appears in the training data. Typical sources:
- Near-duplicate records on both sides of the split.
- Features computed from the label or from future events.
- Preprocessing (scaling, imputation, vocabulary building) fitted on all data before splitting.
Say in the card which checks you ran. "Deduplicated against training set by exact text match" is a concrete claim. "No leakage" is not.
Match the data to the intended use
The evaluation data should resemble the deployment data. This links back to the intended-use section of the card. A classifier meant for live support tickets should be tested on tickets, not on a public review dataset that happens to share the label set. When you can only evaluate on a proxy, say so, and say how the proxy differs.
Report these properties of the evaluation data:
| Property | What to state |
|---|---|
| Source | Where the data came from and how it was sampled |
| Version | Dataset name and version, or a content hash |
| Size | Number of examples, and per-class counts |
| Time range | When the data was collected |
| Preprocessing | Filtering, deduplication, and normalization applied |
| Overlap | How overlap with training data was checked |
| Differences from deployment | Known gaps between this data and real use |
Class balance and sampling
If 95% of examples belong to one class, a model that always predicts that class scores 0.95 accuracy. Report class counts so readers can judge this. If you resampled the test set to balance it, say so, because balanced-set metrics do not predict performance on the real, imbalanced stream. Precision in particular changes with the class ratio.
Choosing metrics
Pick metrics that match the cost of errors
Metrics encode a view of which errors matter. Choose them from the use case, not from habit.
| Metric | Measures | Watch out for |
|---|---|---|
| Accuracy | Share of correct predictions | Misleading on imbalanced classes |
| Precision | Of predicted positives, how many are correct | Depends on class ratio |
| Recall | Of actual positives, how many were found | Ignores false positives |
| F1 | Harmonic mean of precision and recall | Hides which of the two is weak |
| Macro F1 | F1 averaged equally across classes | Rare classes weigh as much as common ones |
| ROC AUC | Ranking quality across all thresholds | Can look good on imbalanced data with poor precision |
| Mean absolute error | Average size of regression errors | Treats all errors linearly |
For a fraud detector, missing fraud (low recall) and blocking good customers (low precision) have different costs, so report both. For a ranking system, report a ranking metric. For a regression model, state the units.
State the threshold and averaging
Precision, recall, and F1 depend on a decision threshold. A card should state the threshold used and, where the threshold can be changed by the deployer, show how the metrics move across thresholds. For multiclass problems, state the averaging method: micro, macro, or weighted. Macro F1 of 0.88 and weighted F1 of 0.88 can describe very different behavior on rare classes.
The following code computes several metrics at an explicit threshold, so the threshold is part of the record.
from sklearn.metrics import precision_score, recall_score, f1_score
y_true = [1, 0, 1, 1, 0, 0, 1, 0, 0, 1]
scores = [0.9, 0.2, 0.65, 0.4, 0.55, 0.1, 0.8, 0.3, 0.45, 0.7]
threshold = 0.5
y_pred = [int(score >= threshold) for score in scores]
report = {
"threshold": threshold,
"precision": round(precision_score(y_true, y_pred), 3),
"recall": round(recall_score(y_true, y_pred), 3),
"f1": round(f1_score(y_true, y_pred), 3),
}
print(report)With these inputs, 4 of 5 predicted positives are correct... and the counts are small, which leads to the next point.
Report uncertainty
A single number from a small test set can move a lot with a different sample. Report a confidence interval or a spread across runs. A bootstrap is a simple way to get one: resample the test set with replacement many times, compute the metric on each sample, and take percentiles.
import random
def bootstrap_interval(y_true, y_pred, metric, n_boot=1000, alpha=0.05, seed=0):
rng = random.Random(seed)
n = len(y_true)
values = []
for _ in range(n_boot):
idx = [rng.randrange(n) for _ in range(n)]
values.append(metric([y_true[i] for i in idx], [y_pred[i] for i in idx]))
values.sort()
low = values[int((alpha / 2) * n_boot)]
high = values[int((1 - alpha / 2) * n_boot) - 1]
return low, high
def accuracy(y_true, y_pred):
return sum(t == p for t, p in zip(y_true, y_pred)) / len(y_true)
y_true = [1, 0, 1, 1, 0, 0, 1, 0, 0, 1]
y_pred = [1, 0, 1, 0, 1, 0, 1, 0, 0, 1]
low, high = bootstrap_interval(y_true, y_pred, accuracy)
print(f"accuracy {accuracy(y_true, y_pred):.2f} (95% CI {low:.2f} to {high:.2f})")With ten examples the interval is wide. That width is the honest message: the test set is too small to support a precise claim. Report the interval, and note the test set size next to it.
Compare against a baseline
A metric needs a reference point. Include at least one baseline: a majority-class predictor, a simple rule, the previous model version, or the system the model replaces. "Macro F1 0.88 versus 0.61 for the keyword-rule baseline" is far more informative than "macro F1 0.88".
Reporting the results
Put the evaluation in a fixed structure
Use the same layout for every model so readers can scan and compare. A table of datasets and metrics works well, followed by a short note on method and caveats.
## Evaluation
### Data
- Dataset: support-tickets-test v3 (hash a41c9e)
- Size: 12,000 tickets, collected Jan–Jun 2025
- Split: by customer; no customer appears in training data
- Deduplication: exact and near-duplicate (Jaccard > 0.9) removal against training set
### Results (threshold 0.5, macro averaged)
| Metric | Value | 95% CI | Baseline (keyword rules) |
|---|---|---|---|
| Accuracy | 0.91 | 0.90 to 0.92 | 0.74 |
| Macro F1 | 0.88 | 0.87 to 0.89 | 0.61 |
### Caveats
- English only. Tickets shorter than 5 words were not evaluated separately.Generate the numbers from code
Hand-typed numbers drift from the model they describe. Write the evaluation script so it emits the results in a structured form that the card generator reads. Store the output next to the model artifact and record the dataset identifier and the code revision.
import json
from datetime import date
def build_eval_record(model_version, dataset, n_examples, metrics, threshold, git_sha):
return {
"model_version": model_version,
"dataset": dataset,
"n_examples": n_examples,
"threshold": threshold,
"metrics": metrics,
"code_revision": git_sha,
"evaluated_on": date.today().isoformat(),
}
record = build_eval_record(
model_version="1.2.0",
dataset="support-tickets-test-v3",
n_examples=12000,
metrics={"accuracy": 0.91, "macro_f1": 0.88},
threshold=0.5,
git_sha="3f2a9c1",
)
print(json.dumps(record, indent=2))This record can feed the metrics field of the model card generator from the earlier chapters, and a later pipeline step can compare it against the previous version.
The evaluation workflow
The diagram shows where each decision falls and where the results flow into the card.
Common errors
- Tuning on the test set. The score is optimistic. Keep a separate validation set and touch the test set once per reported result.
- Reporting only accuracy. On imbalanced data this hides failures. Add precision, recall, and class counts.
- Omitting the threshold. Without it, precision and recall cannot be reproduced.
- No uncertainty. Small test sets produce wide intervals. Hiding them overstates precision.
- Evaluation data unlike deployment data. A strong score on an easy or outdated dataset predicts little about real use.
- Unversioned data. If the test set changes silently, scores across versions are not comparable.
- Reporting only the best run. State how many runs or seeds were used and report the spread.
Exercises
Exercise
A fraud model is tested on a set that is 98% legitimate transactions. It scores 0.98 accuracy. List two additional things the card should report, and explain why.
Show answer
Report precision and recall for the fraud class, and the class counts. A model that labels every transaction legitimate also scores 0.98 accuracy while catching no fraud, so accuracy alone cannot show whether the model works. Precision and recall show how many fraud cases are found and how many alerts are false. Class counts let readers see the imbalance. A baseline such as the majority-class predictor is also useful.
Exercise
Your team splits a customer-churn dataset randomly by row, and each customer has many rows. Test accuracy is 0.97, but accuracy after deployment is 0.83. What likely happened, and how do you fix the evaluation?
Show answer
Rows from the same customer appeared in both training and test sets, so the model saw nearly identical examples during training. This is leakage, and it inflates the test score. Split by customer so that no customer appears on both sides, and, if the data is time-ordered, evaluate on a later time period. Then document the split method in the card.
Exercise
Write the one-line caveat you would add to a card whose evaluation set has 40 examples and a bootstrap 95% interval of 0.71 to 0.96 for recall.
Show answer
"Recall was measured on only 40 examples (95% CI 0.71 to 0.96), so the estimate is imprecise and should be re-measured on a larger set before relying on it."