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)
2/21/2021 10:29:06 AM
Felipe Mendes de Oliveira3 Answers
New AnswerUse 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.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message