precision and recall, performance metrics used to evaluate the effectiveness of certain machine-learning processes. Precision measures the proportion of positive identifications, or “hits,” that were actually correct, and recall measures the proportion of the actual positive values that were identified correctly. Originally developed to assess the performance of information retrieval systems, precision and recall can be used to evaluate machine-learning models concerned with classification, pattern recognition, object detection, and other tasks.
Precision measures the correctness of a model’s positive identifications. The metric, expressed as the fraction of a model’s positive observations that were predicted correctly, denotes quality of identifications and how well they were retrieved. Perfect precision, indicated by a value of 1, means that every object identified as positive was classified correctly and no false positives exist.
Recall measures how well a model captures relevant observations. The metric, expressed as the fraction of actual positive values that were identified correctly, is said to be related to the quantity of identifications and denotes the completeness of their retrieval. Perfect recall, also indicated by a value of 1, means that every relevant observation was identified as such and no positives were ignored.
The measures are based on two binary conditions: first, that each observation belongs in the positive class or not; and second, that each observation has been predicted by the model to be positive or not. Under these two assumptions, each search result falls into one of four categories: positive and identified correctly, known as a true positive (TP); positive but not predicted as such, known as a false negative (FN); not positive and identified as such, known as a true negative (TN); and not positive but predicted incorrectly, known as a false positive (FP).
Precision is then calculated by dividing the number of true positives by the sum of true positives and false positives:Precision = TP/(TP + FP).Recall is then calculated by dividing the number of true positives by the sum of true positives and false negatives:Recall = TP/(TP + FN).
For example, consider the performance of a model that identifies lemons in an image filled with 20 lemons and 20 limes. With lemons as the positive class, the model correctly identifies 16 of the lemons (true positives) but also incorrectly classifies 8 limes as lemons (false positives). The model also correctly ignores 12 of the limes (true negatives) but incorrectly fails to highlight 4 lemons (false negatives).
Therefore, the model’s precision would bePrecision = TP/(TP + FP) = 16/(16 + 8) = 16/24 = 0.667,and the model’s recall would beRecall = TP/(TP + FN) = 16/(16 + 4) = 16/20 = 0.8.
Although high values for both precision and recall are desired for a model, the two measures are inversely related. A trade-off exists when making improvements to precision and recall, as changes that improve one measure typically result in a decrease in the other. For example, lowering the threshold for positive identifications would improve recall by making it less likely for the model to miss positive cases; however, it would also lead to a greater chance of false positives, causing a decrease in precision. Increasing the identification threshold would have the inverse effect: the model’s precision would improve, but its recall would decrease through the higher likelihood of missing positive observations.
In certain contexts, precision and recall may not be valued equally. Precision is more valuable in situations when false positives would be far more costly than false negatives. For models such as spam email detectors, classifying an important email as junk (a false positive) would be much worse than missing a spam email (a false negative). However, for mechanisms that involve the detection of danger, such as security systems, recall is more valuable than precision. For example, high recall is desired for weapon-detecting measures at airports to capture every possible positive, as a false alarm (a false positive) would be much more desirable than missing a threat (a false negative).
Often the metrics are combined into a single performance measure called an F-score, using the following formula:F-score = 2(precision × recall)/(precision + recall).Like precision and recall, F-scores range from 0 (indicating a complete lack of precision, recall, or both measures) to 1 (representing both perfect precision and perfect recall). An F-score cannot be used to evaluate both precision and recall on its own, as the measure does not specify which of the two components has a greater role in driving its value. For example, two models may result in the same F-score even if one struggles in precision and the other in recall.