-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Incorrect calculation from sklearn.metrics.f1_score? #10812
Copy link
Copy link
Closed
Description
Description
The equation for the f1_score is shown here. I think the f1_score calculation from the sklearn.metrics.f1_score is incorrect for the following cases. This website also validate my calculation.
TruePositive, TP = 0
TrueNegative, TN = 10
FalsePositive, FP = 0
FalseNegative, FN = 0
Precision = TP / (TP + FP) = NaN because it's zero division
Recall = TP / (TP + FN) = NaN because it's zero division
F1-Score = 2 * Precision * Recall / (Precision + Recall) = NaN
But sklearn.metrics.f1_score gives an output of 0, which is incorrect
Steps/Code to Reproduce
import numpy as np
import sklearn.metrics as skm
actual = np.zeros(10)
pred = np.zeros(10)
tn, fp, fn, tp = skm.confusion_matrix(actual , pred, labels=[0, 1]).ravel()
f1 = skm.f1_score(actual , pred)
print('TP=', tp) # 0
print('TN=', tn) # 10
print('FP=', fp) # 0
print('FN=', fn) # 0
print('F1=', f1) # 0.0
Expected Results
f1_score should be NaN
Actual Results
But the f1_score calculated from sklearn.metrics.f1_score is 0.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels