- 1

Enter the Matrix Case 5: Help!!

On the Machine Learning course with Python I cannot pass the case 5 test. I have created some mechanisms to avoid the division by 0 but it is not that. tp, fp, fn, tn = [int(x) for x in input().split()] if tp+fp+fn+tn == 0: accuracy = 0 else: accuracy = round((tp+tn)/(tp+fp+fn+tn),4) if tp+fp == 0: precision = 0 else: precision = round((tp)/(tp+fp),4) if tp+fn == 0: recall = 0 else: recall = round((tp)/(tp+fn),4) if precision + recall == 0: f1_score = 0 else: f1_score = round((2*precision*recall)/(precision+recall),4) print(accuracy) print(precision) print(recall) print(f1_score)

21st Feb 2021, 10:29 AM
Felipe Mendes de Oliveira
Felipe Mendes de Oliveira - avatar
3 Réponses
+ 1
Use the round function only in the last e. g. print statement. That should help. Otherwise the "round errors" will add up and you get wrong numbers in the output.
27th Feb 2021, 9:37 PM
StephBill
StephBill - avatar
0
Thanks a lot Bill!!!
28th Feb 2021, 10:15 AM
Felipe Mendes de Oliveira
Felipe Mendes de Oliveira - avatar
0
Test case 5 in wrong
16th Apr 2021, 2:21 AM
Mirchi Tadka
Mirchi Tadka - avatar