Precision and recall describe different mistakes. You can calculate both from the same four counts, but choosing between them requires understanding what a positive prediction means in the task.

Imagine an inspection system evaluating 100 manufactured parts. Ten parts are defective. The model flags eight parts: six are defective and two are fine. It misses four defective parts.

Write the four counts

True positives are the six defective parts correctly flagged. False positives are the two good parts flagged unnecessarily. False negatives are the four defects missed. True negatives are the remaining 88 good parts correctly left unflagged.

The counts should sum to 100. The actual-positive count is 6 + 4 = 10, and the predicted-positive count is 6 + 2 = 8. These checks catch many confusion-matrix mistakes.

Calculate precision

Precision asks: among flagged parts, how many were actually defective? The calculation is 6 / (6 + 2) = 0.75, or 75%.

This describes the reliability of an alert. It does not tell you how many defects went undetected. A system that flags only one obvious defect could have perfect precision and still miss nearly everything else.

Calculate recall

Recall asks: among all defective parts, how many were flagged? The calculation is 6 / (6 + 4) = 0.60, or 60%.

This describes coverage of actual positives. A system that flags every part has perfect recall, but its precision here would be only 10%.

Accuracy and F1

Accuracy is (6 + 88) / 100 = 94%. Yet predicting every part as good would already achieve 90%, because defects are uncommon. Accuracy alone hides much of the failure pattern.

F1 is the harmonic mean of precision and recall. Using counts, it is 2TP / (2TP + FP + FN) = 12 / 18, approximately 0.667. It balances the two ratios, but does not encode every operational cost or use true negatives directly.

Choose a threshold on validation data

Lowering the threshold usually flags more parts, trading fewer misses for more false alarms. The preferred tradeoff depends on inspection capacity and the consequences of each error. Do not repeatedly tune the threshold on the final test set.

If there are no predicted positives, precision has a zero denominator. A reporting tool needs an explicit convention. For multiclass tasks, also specify macro, micro, or weighted averaging; they answer different questions.

See scikit-learn model evaluation and ask the data science bot to compare precision and recall.