# What are correct values for precision and recall in edge cases?

Precision is defined as:

p = true positives / (true positives + false positives)


Is it correct that, as true positives and false positives approach 0, the precision approaches 1?

Same question for recall:

r = true positives / (true positives + false negatives)


I am currently implementing a statistical test where I need to calculate these values, and sometimes it happens that the denominator is 0, and I am wondering which value to return for this case.

P.S.: Excuse the inappropriate tag, I wanted to use recall, precision and limit, but I cannot create new Tags yet.

• I don't think we need limit tag.
– user88
Aug 17, 2010 at 11:08
• Presumably you're attempting to quantify performance of some diagnostic procedure; is there any reason you're not using a proper signal detection theory metric like d', A', or area under the ROC curve? Aug 17, 2010 at 11:19
• @Mike, precision and recall are common evaluation metrics in, e.g., information retrieval where ROC, or in particular specificity is awkward to use because you already expect a high number of false positives. Aug 17, 2010 at 18:02

Given a confusion matrix:

            predicted
(+)   (-)
---------
(+) | TP | FN |
actual      ---------
(-) | FP | TN |
---------


we know that:

Precision = TP / (TP + FP)
Recall = TP / (TP + FN)


Lets consider the cases where the denominator is zero:

• TP+FN=0 : means that there were no positive cases in the input data
• TP+FP=0 : means that all instances were predicted as negative
• Extending your answer: If TP=0 (as in both cases), recall is 1, since the method has discovered all of none true positives; precision is 0 if there is any FP and 1 otherwise.
– user88
Aug 17, 2010 at 11:44
– eod
Dec 9, 2021 at 22:49
• @eod not really, because we don't really compute precision/recall in those case, it's just a special case we test if ({special_case}) return {some_value} else return {computation}. Besides these measures are meaningless when assessing models if for example you don't have positive cases in the data, since they can't distinguish between a good model from a trivial one that always predicts negative.
– Amro
Dec 10, 2021 at 13:35
• Do you have a mathematical proof for this statement? I still don't understand the answer. What I understand is: if we have real=(0,0,0,0), and predicted=(0,0,0,0), then TP=0, TN=4, FP=0, and FN=0. Therefore Recall=0/(0+0)=0/0(=undefined), and Precision=0/(0+0)=0/0(=undefined). I tried to calculate the same case in the R's "caret" package using "confusionMatrix" and it returns "Error in confusionMatrix.default(data = dat$pred, reference = dat$real, : there must be at least 2 factors levels in the data". I didn't check the code, but I hope the error is due to the fact that 0/0=undefined.
– eod
Dec 10, 2021 at 15:54
• there must be at least 2 factors levels in the data the error is telling you that the function expects both positive and negative classes to be represented in the data (two-class problem), again this is checked before doing any computation: github.com/cran/caret/blob/master/R/confusionMatrix.R#L177
– Amro
Dec 13, 2021 at 14:00

Answer is Yes. The undefined edge cases occur when true positives (TP) are 0 since this is in the denominator of both P & R. In this case,

• Recall = 1 when FN=0, since 100% of the TP were discovered
• Precision = 1 when FP=0, since no there were no spurious results

This is a reformulation of @mbq's comment.

I am familiar with different terminology. What you call precision I would positive predictive value (PPV). And what you call recall I would call sensitivity (Sens). :