What is Precision and recall?

Evaluation metrics for two-class classification models. Precision is the fraction of items predicted positive that are actually positive, TP ÷ (TP + FP), and recall is the fraction of actually positive items that were predicted positive, TP ÷ (TP + FN). In general, changing the decision threshold raises one and lowers the other. Their harmonic mean, 2PR ÷ (P + R), is called the F1 score.

Japanese name: 適合率と再現率

Precision and recall appears in 3 practice questions across 1 topic, including Machine Learning Basics.

Field: Machine Learning Basics

Worked example

Suppose there are 100 actually positive items, the model flags 40 items as positive, and 30 of those are truly positive. Precision is 30 ÷ 40 = 0.75 and recall is 30 ÷ 100 = 0.3. The F1 score is 2 × 0.75 × 0.3 ÷ (0.75 + 0.3) ≈ 0.43, lower than the arithmetic mean of about 0.53. The harmonic mean is pulled toward the smaller value, so a model that is good on only one of the two is not rated highly by the F1 score.

Trade-off with the threshold

Many classification models output a score for how likely an item is to be positive and call it positive when the score exceeds a threshold. Raising the threshold makes only confident items positive, so precision tends to rise, while more positives are missed and recall falls. Lowering the threshold does the opposite. The curve of precision against recall as the threshold moves is called the PR curve, and it is used to compare models alongside the ROC curve, which plots the true positive rate against the false positive rate.

Which one to emphasize

In disease screening and defect detection, where a miss is costly, recall is emphasized. When wrongly calling something positive is costly, as in a spam filter that might quarantine an important email, precision is emphasized. Depending on the purpose, the Fβ score, which weights the two differently, may also be used. For imbalanced data with very few positives, these metrics describe performance better than accuracy.

Try it: questions about Precision and recall

A two-class classification model was evaluated on 200 test samples, and its confusion matrix shows 45 true positives (TP), 5 false positives (FP), 45 false negatives (FN) and 105 true negatives (TN). Which pair of precision and recall is correct?

  1. APrecision 0.50, recall 0.90
  2. BPrecision 0.75, recall 0.50
  3. CPrecision 0.90, recall 0.50
Show answer and explanation

Answer: C. Precision 0.90, recall 0.50

Precision is the fraction of items predicted positive that are actually positive: TP ÷ (TP + FP) = 45 ÷ 50 = 0.90. Recall is the fraction of actually positive items that were predicted positive: TP ÷ (TP + FN) = 45 ÷ 90 = 0.50. This model is almost always right when it says positive, but it misses half of the positives. Accuracy is (45 + 105) ÷ 200 = 0.75.

A two-class classification model was evaluated on 200 test samples, giving TP = 20, FP = 5, FN = 30 and TN = 145. Which is closest to the F1 score?

  1. A0.40
  2. B0.53
  3. C0.60
Show answer and explanation

Answer: B. 0.53

First, precision is 20 ÷ (20 + 5) = 0.8 and recall is 20 ÷ (20 + 30) = 0.4. The F1 score is the harmonic mean of precision and recall: 2 × 0.8 × 0.4 ÷ (0.8 + 0.4) = 0.64 ÷ 1.2 ≈ 0.53. The harmonic mean is pulled toward the smaller value, so the F1 score is not high when only one of the two is high. Note that the accuracy, (20 + 145) ÷ 200 = 0.825, looks high, yet this model misses 60% of the positives.

FAQ

How do they differ from accuracy?

Accuracy is the fraction of all predictions that are correct, (TP + TN) ÷ total. On data in which only 1% of items are positive, predicting everything as negative already gives 99% accuracy, but recall is 0, which shows that no positives are found at all.

Are accuracy and precision the same thing?

No. In everyday language the two words are often used loosely, but in classification accuracy is the fraction of all predictions that are correct, while precision is the fraction of positive predictions that are correct. In measurement, precision has yet another meaning: how closely repeated measurements agree with each other.

Precision and recall in the explanations

Questions that mention Precision and recall (3)

  1. A two-class classification model was evaluated on 200 test samples, and its confusion matrix shows 45 true positives (TP), 5 false positives (FP), 45 false negatives (FN) and 105 true negatives (TN). Which pair of precision and recall is correct?
  2. A two-class classification model was evaluated on 200 test samples, giving TP = 20, FP = 5, FN = 30 and TN = 145. Which is closest to the F1 score?
  3. For data of 1000 items of which only 10 are positive, what is the accuracy of a model that predicts every item as negative?

Books on Machine Learning Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Semiconductor, Electronics and Computing Calculators

Related terms

Confusion matrix Harmonic mean Activation function Convolutional neural network (CNN) Cross-validation Gradient descent k-means clustering Overfitting Principal component analysis (PCA) Recurrent neural network (RNN)

Back to the glossary