Learning outcomes
After this lesson, you will be able to:
- Explain the question answered by Accuracy, Precision, Recall and F1.
- Calculate all four metrics from TP, TN, FP and FN in a confusion matrix.
- Explain why Precision and Recall use different denominators.
- Interpret metrics through false alarms and missed cases in a real task.
- Compare models without reducing quality to one number and justify a primary metric.
1. From a confusion matrix to metrics
In lesson 1.5.2, we learned to read a binary classification confusion matrix. Now we will use its counts to calculate metrics. Recall the notation: TP means correctly detected positive cases; TN means correctly identified negative cases; FP means false alarms; and FN means missed positive cases.
A classification metric is a numerical measure describing one aspect of a model’s behaviour on a labelled evaluation set. It is not a universal “intelligence score”: its meaning depends on which cases appear in the numerator and denominator.
This lesson focuses on binary classification with one designated positive class. All four measures are calculated from the same confusion matrix. If the decision threshold used to convert a model score or probability into a class changes, TP, TN, FP and FN change—and the metrics may change with them. We will examine behaviour across thresholds in lesson 1.5.4.
2. Accuracy — the share of all correct predictions
Accuracy answers this question: what fraction of all evaluated objects received the correct prediction, whether their class was positive or negative?
Symbols: TP and TN are correct positive and negative predictions; FP and FN are the two types of errors. The denominator is the entire evaluated set. In plain language, add all correct predictions and divide by the number of objects checked.
In the example from lesson 1.5.2, TP = 18, TN = 168, FP = 12 and FN = 2. There are 18 + 168 = 186 correct predictions out of 200. Therefore, Accuracy = 186 / 200 = 0.93, or 93%.
Accuracy is a useful overall indicator when classes and the costs of different errors are reasonably comparable. However, it can hide serious failures. If the positive class is rare, a model that always predicts “negative” may achieve high Accuracy while detecting none of the cases we care about. Read Accuracy alongside class composition and other metrics. Lesson 1.5.5 will examine rare-class and imbalance problems in more detail.
3. Precision — how reliable positive predictions are
Precision answers: when the model labels an object as positive, how often is that prediction correct? It considers only the objects the model predicted as positive.
Symbols: TP is a correct positive prediction; FP is a false positive prediction. TP + FP counts every positive signal produced by the model. With the same number of correct detections, more false alarms reduce Precision.
In our example, the model produced 30 positive alerts: 18 were correct and 12 were false. Precision = 18 / (18 + 12) = 18 / 30 = 0.60, or 60%. In other words, six out of every ten alerts are confirmed, while four are false alarms.
Precision matters when every positive decision triggers an expensive or time-consuming review—for example, when an expert must inspect every alert manually. High Precision reduces the share of unproductive alerts. But it does not tell us how many actual positive cases the model missed. Recall answers that question.
4. Recall — how many actual positive cases were found
Recall answers a different question: out of all objects that truly belong to the positive class, what fraction did the model detect?
Symbols: TP is a detected positive case; FN is an actual positive case the model missed. TP + FN counts every object that is truly positive. More missed cases reduce Recall.
There were 20 genuinely defective parts in our example: the system detected 18 and missed 2. Recall = 18 / (18 + 2) = 18 / 20 = 0.90, or 90%. The system therefore detected nine out of every ten actual defects.
Recall is important when missing a dangerous event is especially costly: screening, fault detection or threat discovery. But high Recall does not guarantee that positive alerts are accurate. A model may detect nearly every real case at the cost of many false alarms, resulting in low Precision.
The essential distinction: Precision starts with the model’s positive predictions; Recall starts with the actual positive objects. They use different denominators and cannot be substituted for one another.
5. F1 — a joint view of Precision and Recall
Sometimes we need to consider both the reliability of positive predictions and the ability to find actual positive cases. The ordinary arithmetic mean of Precision and Recall can look too favourable when one measure is high and the other is low. F1 provides a different kind of balance.
Here, Precision and Recall are values between 0 and 1. The factor 2 normalizes the harmonic mean so that two perfect values produce F1 = 1. An equivalent expression uses the confusion-matrix counts directly:
There is also a computational edge case: if the model makes no positive predictions, TP + FP = 0 and Precision cannot be calculated by ordinary division. If the evaluation set contains no actual positive cases, TP + FN = 0 and Recall is undefined. Libraries may issue a warning or return 0 or another configured value. A report should state the chosen convention rather than treating it as an ordinary measured result.
In our example, Precision = 0.60 and Recall = 0.90. Therefore, F1 = 2 × 0.60 × 0.90 / (0.60 + 0.90) = 1.08 / 1.50 = 0.72, or 72%. F1 is lower than Recall because Precision is noticeably weaker. This is not a calculation error; it signals an imbalance between the two aspects of positive prediction.
F1 does not directly include TN and does not express the cost of errors in money, time or risk. Nor is it universally the best metric. If a missed event is more costly than a false alarm, Recall may matter more; if false alarms are too expensive, Precision may matter more. F1 is useful when one combined measure of these two qualities is needed and they are treated as equally important.
6. Compare models and choose a measure for the task
Return to the inspection of 200 parts: the set contains 20 defective parts and 180 intact parts. Compare two models on the same evaluation set. Model A is the one from the previous example. Model B detected 16 defects, missed 4, produced 4 false alarms and correctly identified 176 intact parts.
| Measure | Model A | Model B |
|---|---|---|
| TP / TN / FP / FN | 18 / 168 / 12 / 2 | 16 / 176 / 4 / 4 |
| Accuracy | 93% | 96% |
| Precision | 60% | 80% |
| Recall | 90% | 80% |
| F1 | 72% | 80% |
Model B has higher Accuracy, Precision and F1, but lower Recall: it misses four defects instead of two. If the main goal is not to miss a dangerous defect, Model A may be preferable despite producing more false alarms. If manual-review capacity is limited and a missed defect is less costly, Model B may be more practical. The decision depends on the scenario, not on winning the majority of columns.
All measures in this example are calculated using one fixed rule for converting model scores into positive or negative classes. Changing the threshold can change the balance between FP and FN and therefore change Precision, Recall and F1. The next lesson will show how to study this behaviour across many thresholds using ROC and Precision-Recall curves.
7. Practice: calculate all four metrics
A sorting system inspected another batch of 200 products. Independent review produced TP = 42, FP = 8, FN = 18 and TN = 132. First calculate Accuracy, Precision, Recall and F1 on your own. Write each fraction before rounding, then express the result as a percentage.
- How many products did the model classify correctly?
- How many positive alerts did it produce, and what share were correct?
- How many actual defects were detected?
- What is F1, and why is it lower than Precision?
Total objects: 42 + 8 + 18 + 132 = 200. Correct predictions: 42 + 132 = 174. Therefore, Accuracy = 174 / 200 = 87%.
Positive predictions: 42 + 8 = 50. Precision = 42 / 50 = 84%.
Actually positive objects: 42 + 18 = 60. Recall = 42 / 60 = 70%.
F1 = 2 × 0.84 × 0.70 / (0.84 + 0.70) = 1.176 / 1.54 ≈ 76.4%. F1 is below Precision because Recall is noticeably lower. All four values describe the same confusion matrix, but answer different questions.
Conclusion and next step
Accuracy measures the share of all correct predictions. Precision measures the reliability of positive alerts. Recall measures the share of actual positive cases found by the model. F1 combines Precision and Recall using the harmonic mean, but it does not include TN and does not replace an analysis of error costs.
No metric selects a model automatically. First define the positive class and the consequences of FP and FN; then read the confusion matrix, calculate several measures and explain the trade-off. In lesson 1.5.4, we will move from one fixed operating point to ROC-AUC and Precision-Recall AUC, which describe model behaviour as the decision threshold changes.
Sources and further reading
- Google for Developers — Accuracy, Precision, Recall and related metrics. Explanations of denominators, trade-offs and practical metric selection.
- scikit-learn — Metrics and scoring: quantifying the quality of predictions. Formal definitions and classification-metric options.
- Sokolova, M. and Lapalme, G. (2009). A systematic analysis of performance measures for classification tasks. Information Processing & Management, 45(4), 427–437.
Key terms
Knowledge check
Choose one answer for each question. An explanation appears after you select Check answer.
Question 1
Which values appear in the denominator of Accuracy?
Question 2
Which denominator does Precision use?
Question 3
What does Recall measure?
Question 4
For TP = 18, TN = 168, FP = 12 and FN = 2, what is Accuracy?
Question 5
Which description of F1 is correct?
Question 6
Which metric should receive special attention if missing an actual defect is the most costly error?
Question 7
If the main goal is to miss as few defects as possible, which model is preferable in the lesson comparison?