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.
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 ...
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.
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.
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%.
Yes, this is possible. Let's assume binary classification with
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
If Pr = Re
, again all three metrics are identical.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With