Last active
January 30, 2022 11:47
-
-
Save sunilkumardash9/1630689b4ae1c33a20a29f409631b592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def F1_score(y,y_hat): | |
tp,tn,fp,fn = 0,0,0,0 | |
for i in range(len(y)): | |
if y[i] == 1 and y_hat[i] == 1: | |
tp += 1 | |
elif y[i] == 1 and y_hat[i] == 0: | |
fn += 1 | |
elif y[i] == 0 and y_hat[i] == 1: | |
fp += 1 | |
elif y[i] == 0 and y_hat[i] == 0: | |
tn += 1 | |
precision = tp/(tp+fp) | |
recall = tp/(tp+fn) | |
f1_score = 2*precision*recall/(precision+recall) | |
return f1_score |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment