- 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)
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.
0
Thanks a lot Bill!!!
0
Test case 5 in wrong