Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the Precision, Recall and F1 be the same value?

I am currently working on an ML classification problem and I'm computing the Precision, Recall and F1 using the sklearn library's following import and respective code as shown below.

from sklearn.metrics import precision_recall_fscore_support

print(precision_recall_fscore_support(y_test, prob_pos, average='weighted'))

Results

0.8806451612903226, 0.8806451612903226, 0.8806451612903226

Is there a possibility to get the same value for all 3, the precision, recall and F1 for an ML classification problem?

Any clarifications in this regard will be much appreciated.

like image 995
Nayantara Jeyaraj Avatar asked Jan 07 '19 03:01

Nayantara Jeyaraj


People also ask

Can precision and recall both be 1?

In information retrieval, a perfect precision score of 1.0 means that every result retrieved by a search was relevant (but says nothing about whether all relevant documents were retrieved) whereas a perfect recall score of 1.0 means that all relevant documents were retrieved by the search (but says nothing about how ...

What does it mean if precision and recall are equal?

If precision and recall are equal, we have p=r, and since they have the same denominator, we get fp=fn. This means that our algorithm has classified an equal amount of users as false positives, as it classified false negatives.

Can accuracy precision and recall be same?

Therefore, precision is close to TP/TP=1. The recall formula doesn't change since neither TP nor FN is close to 0. Accuracy which is (TP+TN)/(TP+TN+FP+FN) is close to TP/(TP+FN) which is recall.

Can F1 score be lower than precision and recall?

Similar to arithmetic mean, the F1-score will always be somewhere in between precision and recall. But it behaves differently: the F1-score gives a larger weight to lower numbers. For example, when Precision is 100% and Recall is 0%, the F1-score will be 0%, not 50%.


2 Answers

Yes, this is possible. Let's assume binary classification with

Pr = TP  / (TP + FP); Re = (TP + FN); F1 = 2TP / (2TP + FP + FN)

The trivial solution to Pr = Re = F1 is TP = 0. So we know precision, recall and F1 can have the same value in general. Now, this does not apply to your specific result. If we solve the system of equations, we find another solution: FP = FN. So, if the number of false positives is the same as the number of false negatives, all three metrics have identical values.

For multiclass classification problems we have

F1 = 2 * (Pr * Re) / (Pr + Re)

If Pr = Re, again all three metrics are identical.

like image 166
rvf Avatar answered Sep 30 '22 09:09

rvf


This seems to be because of the option - average='weighted'

Refer: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_fscore_support.html

'weighted': Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters ‘macro’ to account for label imbalance; it can result in an F-score that is not between precision and recall.

like image 34
Ankita Mehta Avatar answered Sep 30 '22 08:09

Ankita Mehta