Skip to content
Raisalon

Machine Learning

Why a classifier can have 99% accuracy and zero recall

Reproduce 99% accuracy and zero positive-class recall in scikit-learn. Read the confusion matrix and see the cost of changing the decision threshold.

Author
4 min read

A classifier can have 99% accuracy and zero recall when one in every hundred cases is positive and the classifier predicts negative every time. It gets 99 decisions right and misses the single case you wanted to find. A confusion matrix shows where those two percentages come from and helps you decide what to change.

Start with the queue the model produces

Imagine a team that manually reviews orders flagged for a packing error. During a small evaluation, 99 orders were packed correctly and one had an error. The model flagged nothing. Its empty review queue might look efficient until the team checks which order went out incorrectly.

Actual outcome Predicted normal Predicted packing error
Normal 99 true negatives 0 false positives
Packing error 1 false negative 0 true positives

Accuracy divides the number of correct decisions by all 100 orders. Positive-class recall asks what fraction of the actual packing errors the model caught. Its denominator is one. Precision asks how often a flag was correct. Here the model raised zero flags, so precision has a zero denominator. That distinction matters when reading a dashboard that displays zero for both recall and precision.

Reproduce the report in scikit-learn

Run this example in Python with scikit-learn installed. The labels argument fixes the row and column order even if a later batch contains just one class. Rows in the printed matrix represent actual outcomes, and columns represent predictions. Label 1 means a packing error.

from sklearn.metrics import (
    accuracy_score, balanced_accuracy_score, classification_report,
    confusion_matrix, recall_score,
)

actual = [0] * 99 + [1]
predicted = [0] * 100

print(confusion_matrix(actual, predicted, labels=[0, 1]))
print("Accuracy:", accuracy_score(actual, predicted))
print("Error recall:", recall_score(actual, predicted, pos_label=1))
print("Balanced accuracy:", balanced_accuracy_score(actual, predicted))
print(classification_report(actual, predicted, labels=[0, 1], zero_division=0))

The three scores are 0.99, 0 and 0.5. Balanced accuracy averages the recall of each class. The model caught every normal order and zero packing errors, so the two classes contribute 1 and 0 respectively. The report’s weighted average gives the 99 normal orders much more influence. Check the row for the class you care about and its support, the count of actual cases in that class. scikit-learn model evaluation guide

The zero_division=0 option sets how the report displays undefined ratios. It doesn’t create evidence about precision. When your test set contains zero actual positives, recall itself becomes undefined. Label that situation separately from a model that missed an observed positive. A count of actual positives beside the percentage makes the distinction visible.

Move the threshold and count the work

Suppose the model also returns a score for each order. The packing error scores 0.42, eight normal orders score 0.35, and the remaining 91 normal orders score 0.02. These are illustrative scores. Flag an order whenever its score equals or exceeds the chosen threshold.

Threshold Orders flagged Errors found Accuracy Error recall
0.50 0 0 of 1 99% 0%
0.40 1 1 of 1 100% 100%
0.30 9 1 of 1 92% 100%

At 0.30 the team inspects nine orders to catch one error. Precision is one ninth, about 11%. A team with capacity for three inspections would face a different decision from one that can inspect all nine. You can reproduce that row with 1 true positive, 8 false positives, 0 false negatives and 91 true negatives in the classification metrics calculator.

Check which class the report treats as positive

Suppose the label encoder maps "packing_error" to 0 and "normal" to 1. Calling a binary recall function with its default positive label of 1 now reports how many normal orders you recognized. That number can be excellent while every packing error is missed. Print the encoder’s mapping, a few raw labels and the predicted values together before making a threshold change. If the model exposes probabilities as an array, find the column corresponding to the class you intend to flag.

Inspect the split as well. If the same order appears twice after a join, or orders from the same customer leak across partitions, the evaluation can measure an easier task than the one your team faces. A customer-level holdout is one way to check performance on unfamiliar customers.

Finally, write the counts alongside any comparison you send to the review team. “Caught one of one errors with nine inspections” tells a colleague both what happened and how little evidence went into the percentage. “100% recall” on its own doesn’t give them enough information to staff tomorrow’s queue.

Next steps

Check the label mapping and support first. Then inspect the scores of missed positives on a validation set. If positives tend to score above negatives, adjusting the threshold may help. If many examples share the same score, a threshold cannot separate them. Review features, labels and data collection before promising a recall target. Select the threshold on validation data and evaluate it once on a separate holdout. A single observed positive is enough to explain the arithmetic and far too few to establish dependable recall. scikit-learn guide to decision thresholds

Share

Written by