Sub topic 6
Choosing and Reporting Evaluation Data and Metrics
Assume you know the difference between training, validation, and test sets. You should also know basic classification metrics such as accuracy, precision, recall, and F1 score. This chapter focuses on choosing evaluation data that supports a trustworthy claim and reporting metrics so that another person can interpret the claim.
Start with the question the evaluation must answer
An evaluation metric is a numerical summary of model behavior. It does not describe the model by itself. It describes how the model behaved on particular data, under particular conditions.
Begin by writing the decision that the model will support:
- What is the model predicting?
- Which errors are costly?
- Who or what will be affected by those errors?
- What conditions will the model encounter after deployment?
- What level of performance is acceptable?
For example, a support-ticket classifier may route messages to queues. Sending a billing question to the technical-support queue is inconvenient. Sending a safety report to an unattended queue may be much more serious. A single accuracy value cannot express that difference.
Choose evaluation data carefully
A test set should represent the data and conditions expected after deployment. “Representative” includes more than the same label proportions. Consider language, geography, device type, time period, input length, and unusual cases.
Keep the test set separate from training and model-selection decisions. If you repeatedly inspect test results and change the model, the test set gradually becomes part of the training process. Use a validation set for ordinary experimentation, then evaluate once on a protected test set.
Time can also matter. If the data distribution changes, use a temporal test set: train on earlier examples and test on later examples. This better estimates performance after release than a random split does.
Record the evaluation data in the model card:
- Source and collection period
- Number of examples
- Label definitions
- Inclusion and exclusion rules
- Train, validation, and test split method
- Known differences from production data
- Any filtering, preprocessing, or deduplication
Match metrics to error costs
For a binary classifier, a true positive is a positive case predicted as positive. A false positive is a negative case predicted as positive. A false negative is a positive case predicted as negative.
| Metric | What it measures | Useful when |
|---|---|---|
| Accuracy | Fraction of all predictions that are correct | Classes and error costs are fairly balanced |
| Precision | Fraction of predicted positives that are truly positive | False alarms are expensive |
| Recall | Fraction of actual positives that are found | Missed positives are expensive |
| F1 score | Harmonic mean of precision and recall | Both error types matter |
Accuracy can hide poor behavior when one class is common. If only 5% of tickets are urgent, a model that never identifies urgent tickets can still reach 95% accuracy. Report the positive-class rate and metrics that reflect the operational goal.
The classification threshold also changes precision and recall. A lower threshold usually finds more positive cases, increasing recall but often reducing precision. State the threshold or explain how it was selected.
Compute and report metrics
The following example computes binary metrics without an external library:
def binary_metrics(y_true, y_pred):
tp = sum(actual == 1 and predicted == 1
for actual, predicted in zip(y_true, y_pred))
fp = sum(actual == 0 and predicted == 1
for actual, predicted in zip(y_true, y_pred))
fn = sum(actual == 1 and predicted == 0
for actual, predicted in zip(y_true, y_pred))
tn = sum(actual == 0 and predicted == 0
for actual, predicted in zip(y_true, y_pred))
total = tp + fp + fn + tn
accuracy = (tp + tn) / total if total else 0.0
precision = tp / (tp + fp) if tp + fp else 0.0
recall = tp / (tp + fn) if tp + fn else 0.0
f1 = (
2 * precision * recall / (precision + recall)
if precision + recall else 0.0
)
return {
"accuracy": accuracy,
"precision": precision,
"recall": recall,
"f1": f1,
"support": total,
}
truth = [1, 1, 1, 0, 0, 0]
predictions = [1, 0, 1, 1, 0, 0]
print(binary_metrics(truth, predictions))A model card should report the sample count with each metric. For important metrics, include uncertainty, such as a confidence interval, and explain the method used. Small test sets can produce unstable results.
Make the evaluation reproducible
A useful evaluation record includes the model version, dataset version, preprocessing version, random seed when relevant, metric definitions, and evaluation date. Store the evaluation code with the model and review changes to the test data.
Exercise
A classifier reports 98% accuracy, but the positive class makes up only 2% of the test set. What additional result should you request first?
Show answer
Request precision and recall for the positive class, along with the class counts. Accuracy may be high even if the model misses nearly every positive case.