Precision and recall

From HandWiki
Short description: Pattern-recognition performance metrics
Precision and recall

In pattern recognition, information retrieval, object detection and classification (machine learning), precision and recall are performance metrics that apply to data retrieved from a collection, corpus or sample space.

Precision (also called positive predictive value) is the fraction of relevant instances among the retrieved instances. Written as a formula:

[math]\displaystyle{ \text{Precision} = \frac{\text{Relevant retrieved instances}}{\text{All retrieved instances}} }[/math]

Recall (also known as sensitivity) is the fraction of relevant instances that were retrieved. Written as a formula:

[math]\displaystyle{ \text{Recall} = \frac{\text{Relevant retrieved instances}}{\text{All relevant instances}} }[/math]

Both precision and recall are therefore based on relevance.

Consider a computer program for recognizing dogs (the relevant element) in a digital photograph. Upon processing a picture which contains ten cats and twelve dogs, the program identifies eight dogs. Of the eight elements identified as dogs, only five actually are dogs (true positives), while the other three are cats (false positives). Seven dogs were missed (false negatives), and seven cats were correctly excluded (true negatives). The program's precision is then 5/8 (true positives / selected elements) while its recall is 5/12 (true positives / relevant elements).

Adopting a hypothesis-testing approach from statistics, in which, in this case, the null hypothesis is that a given item is irrelevant (i.e., not a dog), absence of type I and type II errors (i.e., perfect specificity and sensitivity of 100% each) corresponds respectively to perfect precision (no false positive) and perfect recall (no false negative).

More generally, recall is simply the complement of the type II error rate (i.e., one minus the type II error rate). Precision is related to the type I error rate, but in a slightly more complicated way, as it also depends upon the prior distribution of seeing a relevant vs. an irrelevant item.

The above cat and dog example contained 8 − 5 = 3 type I errors (false positives) out of 10 total cats (true negatives), for a type I error rate of 3/10, and 12 − 5 = 7 type II errors (false negatives), for a type II error rate of 7/12. Precision can be seen as a measure of quality, and recall as a measure of quantity. Higher precision means that an algorithm returns more relevant results than irrelevant ones, and high recall means that an algorithm returns most of the relevant results (whether or not irrelevant ones are also returned).

Introduction

In a classification task, the precision for a class is the number of true positives (i.e. the number of items correctly labelled as belonging to the positive class) divided by the total number of elements labelled as belonging to the positive class (i.e. the sum of true positives and false positives, which are items incorrectly labelled as belonging to the class). Recall in this context is defined as the number of true positives divided by the total number of elements that actually belong to the positive class (i.e. the sum of true positives and false negatives, which are items which were not labelled as belonging to the positive class but should have been).


Precision and recall are not particularly useful metrics when used in isolation. For instance, it is possible to have perfect recall by simply retrieving every single item. Likewise, it is possible to have near-perfect precision by selecting only a very small number of extremely likely items.

In a classification task, a precision score of 1.0 for a class C means that every item labelled as belonging to class C does indeed belong to class C (but says nothing about the number of items from class C that were not labelled correctly) whereas a recall of 1.0 means that every item from class C was labelled as belonging to class C (but says nothing about how many items from other classes were incorrectly also labelled as belonging to class C).

Often, there is an inverse relationship between precision and recall, where it is possible to increase one at the cost of reducing the other. Brain surgery provides an illustrative example of the tradeoff. Consider a brain surgeon removing a cancerous tumor from a patient's brain. The surgeon needs to remove all of the tumor cells since any remaining cancer cells will regenerate the tumor. Conversely, the surgeon must not remove healthy brain cells since that would leave the patient with impaired brain function. The surgeon may be more liberal in the area of the brain they remove to ensure they have extracted all the cancer cells. This decision increases recall but reduces precision. On the other hand, the surgeon may be more conservative in the brain cells they remove to ensure they extracts only cancer cells. This decision increases precision but reduces recall. That is to say, greater recall increases the chances of removing healthy cells (negative outcome) and increases the chances of removing all cancer cells (positive outcome). Greater precision decreases the chances of removing healthy cells (positive outcome) but also decreases the chances of removing all cancer cells (negative outcome).

Usually, precision and recall scores are not discussed in isolation. A precision-recall curve plots precision as a function of recall; usually precision will decrease as the recall increases. Alternatively, values for one measure can be compared for a fixed level at the other measure (e.g. precision at a recall level of 0.75) or both are combined into a single measure. Examples of measures that are a combination of precision and recall are the F-measure (the weighted harmonic mean of precision and recall), or the Matthews correlation coefficient, which is a geometric mean of the chance-corrected variants: the regression coefficients Informedness (DeltaP') and Markedness (DeltaP).[1][2] Accuracy is a weighted arithmetic mean of Precision and Inverse Precision (weighted by Bias) as well as a weighted arithmetic mean of Recall and Inverse Recall (weighted by Prevalence).[1] Inverse Precision and Inverse Recall are simply the Precision and Recall of the inverse problem where positive and negative labels are exchanged (for both real classes and prediction labels). True Positive Rate and False Positive Rate, or equivalently Recall and 1 - Inverse Recall, are frequently plotted against each other as ROC curves and provide a principled mechanism to explore operating point tradeoffs. Outside of Information Retrieval, the application of Recall, Precision and F-measure are argued to be flawed as they ignore the true negative cell of the contingency table, and they are easily manipulated by biasing the predictions.[1] The first problem is 'solved' by using Accuracy and the second problem is 'solved' by discounting the chance component and renormalizing to Cohen's kappa, but this no longer affords the opportunity to explore tradeoffs graphically. However, Informedness and Markedness are Kappa-like renormalizations of Recall and Precision,[3] and their geometric mean Matthews correlation coefficient thus acts like a debiased F-measure.

Definition

For classification tasks, the terms true positives, true negatives, false positives, and false negatives (see Type I and type II errors for definitions) compare the results of the classifier under test with trusted external judgments. The terms positive and negative refer to the classifier's prediction (sometimes known as the expectation), and the terms true and false refer to whether that prediction corresponds to the external judgment (sometimes known as the observation).

Let us define an experiment from P positive instances and N negative instances for some condition. The four outcomes can be formulated in a 2×2 contingency table or confusion matrix, as follows:


Precision and recall are then defined as:[4]

[math]\displaystyle{ \begin{align} \text{Precision} &= \frac{tp}{tp + fp} \\ \text{Recall} &= \frac{tp}{tp + fn} \, \end{align} }[/math]

Recall in this context is also referred to as the true positive rate or sensitivity, and precision is also referred to as positive predictive value (PPV); other related measures used in classification include true negative rate and accuracy.[4] True negative rate is also called specificity.

[math]\displaystyle{ \text{True negative rate} = \frac{tn}{tn + fp} \, }[/math]

When to use precision versus recall

They are both useful in cases where there is imbalanced data. Use precision when the cost of false positives is high: In situations where misclassifying an instance as positive has serious consequences, precision is a better choice. For example, in medical diagnosis, mistakenly diagnosing a healthy person with a disease can lead to unnecessary treatment and expenses. Use recall when the cost of false negatives is high: When the consequence of misclassifying an instance as negative is severe, recall is a better choice. For example, in fraud detection, failing to detect a fraudulent transaction can result in significant financial loss. It's a matter of values: some might believe that health requires greater precision, as it is irreplaceable, while the financial system may need higher recall, because an unfair judgment can lead to irreparable consequences such as the loss of a job, a house, or even result in suicide.

Probabilistic Definition

Precision and recall can be interpreted as (estimated) conditional probabilities:[5] Precision is given by [math]\displaystyle{ \mathbb{P}(C=P|\hat{C}=P) }[/math] while recall is given by [math]\displaystyle{ \mathbb{P}(\hat{C}=P|C=P) }[/math],[6] where [math]\displaystyle{ \hat{C} }[/math] is the predicted class and [math]\displaystyle{ C }[/math] is the actual class (i.e. [math]\displaystyle{ C=P }[/math] means the actual class is positive). Both quantities are, therefore, connected by Bayes' theorem.

No-Skill Classifiers

The probabilistic interpretation allows to easily derive how a no-skill classifier would perform. A no-skill classifiers is defined by the property that the conditional probability[math]\displaystyle{ \mathbb{P}(C=P,\hat{C}=P)=\mathbb{P}(C=P)\mathbb{P}(\hat{C}=P) }[/math] is just the product of the unconditional probabilites since the classification and the presence of the class are independent.

For example the precision of a no-skill classifier is simply a constant [math]\displaystyle{ \mathbb{P}(C=P|\hat{C}=P)=\frac{\mathbb{P}(C=P,\hat{C}=P)}{\mathbb{P}(\hat{C}=P)}=\mathbb{P}(C=P), }[/math] i.e. determined by the probability/frequency with which the class P occurs.

A similar argument can be made for the recall: [math]\displaystyle{ \mathbb{P}(\hat{C}=P|C=P)=\frac{\mathbb{P}(C=P,\hat{C}=P)}{\mathbb{P}(C=P)}=\mathbb{P}(\hat{C}=P) }[/math] which is just (the typically threshold dependent) probability for a positive classification.

Some very specific no-skill classifiers are implemented in sklearn and are named dummy classifiers there.[7]

Imbalanced data

[math]\displaystyle{ \text{Accuracy}=\frac{TP+TN}{TP+TN+FP+FN} \, }[/math]

Accuracy can be a misleading metric for imbalanced data sets. Consider a sample with 95 negative and 5 positive values. Classifying all values as negative in this case gives 0.95 accuracy score. There are many metrics that don't suffer from this problem. For example, balanced accuracy[8] (bACC) normalizes true positive and true negative predictions by the number of positive and negative samples, respectively, and divides their sum by two:

[math]\displaystyle{ \text{Balanced accuracy}= \frac{TPR + TNR}{2}\, }[/math]

For the previous example (95 negative and 5 positive samples), classifying all as negative gives 0.5 balanced accuracy score (the maximum bACC score is one), which is equivalent to the expected value of a random guess in a balanced data set. Balanced accuracy can serve as an overall performance metric for a model, whether or not the true labels are imbalanced in the data, assuming the cost of FN is the same as FP.

The TPR and FPR are a property of a given classifier operating at a specific threshold. However, the overall number of TPs, FPs etc depend on the class imbalance in the data via the class ratio [math]\displaystyle{ r = P/N }[/math]. As the recall (or TPR) depends only on positive cases, it is not affected by [math]\displaystyle{ r }[/math], but the precision is. We have that

[math]\displaystyle{ \text{Precision} = \frac{TP}{TP+FP} = \frac{P \cdot TPR}{P \cdot TPR+ N \cdot FPR} = \frac{TPR}{TPR+ \frac{1}{r} FPR}. }[/math]

Thus the precision has an explicit dependence on [math]\displaystyle{ r }[/math].[9] Starting with balanced classes at [math]\displaystyle{ r =1 }[/math] and gradually decreasing [math]\displaystyle{ r }[/math], the corresponding precision will decrease, because the denominator increases.

Another metric is the predicted positive condition rate (PPCR), which identifies the percentage of the total population that is flagged. For example, for a search engine that returns 30 results (retrieved documents) out of 1,000,000 documents, the PPCR is 0.003%.

[math]\displaystyle{ \text{Predicted positive condition rate}=\frac{TP+FP}{TP+FP+TN+FN} \, }[/math]

According to Saito and Rehmsmeier, precision-recall plots are more informative than ROC plots when evaluating binary classifiers on imbalanced data. In such scenarios, ROC plots may be visually deceptive with respect to conclusions about the reliability of classification performance.[10]

Different from the above approaches, if an imbalance scaling is applied directly by weighting the confusion matrix elements, the standard metrics definitions still apply even in the case of imbalanced datasets.[11] The weighting procedure relates the confusion matrix elements to the support set of each considered class.


F-measure

A measure that combines precision and recall is the harmonic mean of precision and recall, the traditional F-measure or balanced F-score:

[math]\displaystyle{ F = 2 \cdot \frac{\mathrm{precision} \cdot \mathrm{recall}}{ \mathrm{precision} + \mathrm{recall}} }[/math]

This measure is approximately the average of the two when they are close, and is more generally the harmonic mean, which, for the case of two numbers, coincides with the square of the geometric mean divided by the arithmetic mean. There are several reasons that the F-score can be criticized, in particular circumstances, due to its bias as an evaluation metric.[1] This is also known as the [math]\displaystyle{ F_1 }[/math] measure, because recall and precision are evenly weighted.

It is a special case of the general [math]\displaystyle{ F_\beta }[/math] measure (for non-negative real values of [math]\displaystyle{ \beta }[/math]):

[math]\displaystyle{ F_\beta = (1 + \beta^2) \cdot \frac{\mathrm{precision} \cdot \mathrm{recall} }{ \beta^2 \cdot \mathrm{precision} + \mathrm{recall}} }[/math]

Two other commonly used [math]\displaystyle{ F }[/math] measures are the [math]\displaystyle{ F_2 }[/math] measure, which weights recall higher than precision, and the [math]\displaystyle{ F_{0.5} }[/math] measure, which puts more emphasis on precision than recall.

The F-measure was derived by van Rijsbergen (1979) so that [math]\displaystyle{ F_\beta }[/math] "measures the effectiveness of retrieval with respect to a user who attaches [math]\displaystyle{ \beta }[/math] times as much importance to recall as precision". It is based on van Rijsbergen's effectiveness measure [math]\displaystyle{ E_{\alpha} = 1 - \frac{1}{\frac{\alpha}{P} + \frac{1-\alpha}{R}} }[/math], the second term being the weighted harmonic mean of precision and recall with weights [math]\displaystyle{ (\alpha, 1-\alpha) }[/math]. Their relationship is [math]\displaystyle{ F_\beta = 1 - E_{\alpha} }[/math] where [math]\displaystyle{ \alpha=\frac{1}{1 + \beta^2} }[/math].

Limitations as goals

There are other parameters and strategies for performance metric of information retrieval system, such as the area under the ROC curve (AUC)[12] or pseudo-R-squared.

See also

References

  1. 1.0 1.1 1.2 1.3 Powers, David M W (2011). "Evaluation: From Precision, Recall and F-Measure to ROC, Informedness, Markedness & Correlation". Journal of Machine Learning Technologies 2 (1): 37–63. http://www.flinders.edu.au/science_engineering/fms/School-CSEM/publications/tech_reps-research_artfcts/TRRA_2007.pdf. 
  2. Perruchet, P.; Peereman, R. (2004). "The exploitation of distributional information in syllable processing". J. Neurolinguistics 17 (2–3): 97–119. doi:10.1016/s0911-6044(03)00059-9. 
  3. Powers, David M. W. (2012). "The Problem with Kappa". https://www.aclweb.org/anthology/E12-1035. 
  4. 4.0 4.1 Olson, David L.; and Delen, Dursun (2008); Advanced Data Mining Techniques, Springer, 1st edition (February 1, 2008), page 138, ISBN:3-540-76916-1
  5. Fatih Cakir, Kun He, Xide Xia, Brian Kulis, Stan Sclaroff, Deep Metric Learning to Rank, In Proc. IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2019.
  6. Roelleke, Thomas (2022-05-31) (in en). Information Retrieval Models: Foundations & Relationships. Springer Nature. ISBN 978-3-031-02328-6. https://books.google.com/books?id=YX9yEAAAQBAJ&pg=PA76. 
  7. "Sklearn.dummy.DummyClassifier". https://scikit-learn.org/stable/modules/generated/sklearn.dummy.DummyClassifier.html. 
  8. Mower, Jeffrey P. (2005-04-12). "PREP-Mt: predictive RNA editor for plant mitochondrial genes". BMC Bioinformatics 6: 96. doi:10.1186/1471-2105-6-96. ISSN 1471-2105. PMID 15826309. 
  9. Williams, Christopher K. I. (2021-04-01). "The Effect of Class Imbalance on Precision-Recall Curves". Neural Computation 33 (4): 853–857. doi:10.1162/neco_a_01362. ISSN 0899-7667. https://doi.org/10.1162/neco_a_01362. 
  10. Saito, Takaya; Rehmsmeier, Marc (2015-03-04). Brock, Guy. ed. "The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets" (in en). PLOS ONE 10 (3): e0118432. doi:10.1371/journal.pone.0118432. ISSN 1932-6203. PMID 25738806. Bibcode2015PLoSO..1018432S. 
  11. Tripicchio, Paolo; Camacho-Gonzalez, Gerardo; D'Avella, Salvatore (2020). "Welding defect detection: coping with artifacts in the production line". The International Journal of Advanced Manufacturing Technology 111 (5): 1659–1669. doi:10.1007/s00170-020-06146-4. https://link.springer.com/article/10.1007/s00170-020-06146-4. 
  12. Zygmunt Zając. What you wanted to know about AUC. http://fastml.com/what-you-wanted-to-know-about-auc/
  • Baeza-Yates, Ricardo; Ribeiro-Neto, Berthier (1999). Modern Information Retrieval. New York, NY: ACM Press, Addison-Wesley, Seiten 75 ff. ISBN:0-201-39829-X
  • Hjørland, Birger (2010); The foundation of the concept of relevance, Journal of the American Society for Information Science and Technology, 61(2), 217-237
  • Makhoul, John; Kubala, Francis; Schwartz, Richard; and Weischedel, Ralph (1999); Performance measures for information extraction, in Proceedings of DARPA Broadcast News Workshop, Herndon, VA, February 1999
  • van Rijsbergen, Cornelis Joost "Keith" (1979); Information Retrieval, London, GB; Boston, MA: Butterworth, 2nd Edition, ISBN:0-408-70929-4

External links