0
Machine Learning Model Evaluation Module :: project :: Welcome to the Matrix Test case 5
help plezz i am trying to run this code and it passed all test cases except 5 which is hidden : tp, fp, fn, tn = [int(x) for x in input().split()] total = tp + fp + fn + tn accuracy = round((tp + tn) / total,4) precision = round(tp / (tp + fp) ,4) recall = round(tp / (tp + fn),4) f1 = round( 2 * precision * recall / (precision + recall) ,4) print(accuracy) print(precision) print(recall) print(f1)
11 Antworten
+ 11
Round in the print statement, not on "the way" - rounding errors may occur else ways
Rounding errors are adding up
For example, if we take 1.3 as précision and recall and round them both to whole numbers when we calculate them. => we get 1, 1*1 =1
instead of 1.3*1.3 = 1.69 =>rounded to 2
+ 11
As StephBill said, I rounded in the print statement and not on the way (it worked!):
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp+ fp+ fn+ tn
accuracy = (tp + tn )/(total) #round(x, 4)
precision = tp/ (tp+fp)
recall = tp/ (tp+fn)
f1 = round(1/(((1/precision) + (1/recall)) / 2), 4)
print(round(accuracy, 4))
print(round(precision, 4))
print(round(recall, 4))
print(f1)
+ 1
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp + fp + fn + tn
accuracy = round((tp + tn) / total,4)
precision = round(tp / (tp + fp) ,4)
recall = round(tp / (tp + fn),4)
f1 = round( 2 * precision * recall / (precision + recall) ,4)
print(accuracy)
print(precision)
print(recall)
print(f1)
not working
test case 5 is hidden and shows wrong
+ 1
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp+ fp+ fn+ tn
accuracy = (tp + tn )/(total) #round(x, 4)
precision = tp/ (tp+fp)
recall = tp/ (tp+fn)
f1 = round(1/(((1/precision) + (1/recall)) / 2), 4)
print(round(accuracy, 4))
print(round(precision, 4))
print(round(recall, 4))
print(f1)
0
please answer for this problem.
0
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp+ fp+ fn+ tn
accuracy = (tp + tn )/(total) #round(x, 4)
precision = tp/ (tp+fp)
recall = tp/ (tp+fn)
f1 = round(1/(((1/precision) + (1/recall)) / 2), 4)
print(round(accuracy, 4))
print(round(precision, 4))
print(round(recall, 4))
print(f1)
0
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp+ fp+ fn+ tn
accuracy = (tp + tn )/(total) #round(x, 4)
precision = tp/ (tp+fp)
recall = tp/ (tp+fn)
f1 = round(1/(((1/precision) + (1/recall)) / 2), 4)
print(round(accuracy, 4))
print(round(precision, 4))
print(round(recall, 4))
print(f1)
0
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp+ fp+ fn+ tn
accuracy = (tp + tn )/(total) #round(x, 4)
precision = tp/ (tp+fp)
recall = tp/ (tp+fn)
f1 = round(1/(((1/precision) + (1/recall)) / 2), 4)
print(round(accuracy, 4))
print(round(precision, 4))
print(round(recall, 4))
print(f1)
0
I passed all the test cases using these codes, I hope this might help you
tp, fp, fn, tn = [int(x) for x in input().split()]
ac = (tp + tn) / (tp+fp+fn+tn)
pr = tp / (tp + fp)
re = tp / (tp + fn)
f1 = (2 * pr * re) / (pr + re)
output = [ac, pr, re, f1]
for i in output:
print(round(i, 4))
0
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp + tn + fp + fn
#Accuracy is (tp + tn) / total
accuracy = (tp + tn) / total
#Precision is tp / (tp + fp)
precision = tp / (tp + fp)
#Recall is tp / (tp + fn)
recall = tp / (tp + fn)
#F1 score is 2 * precision * recall / (precision + recall)
f1 = 2 * precision * recall / (precision + recall)
print(round(accuracy, 4))
print(round(precision, 4))
print(round(recall, 4))
print(round(f1, 4))
0
tp, fp, fn, tn = [int(x) for x in input().split()]
total = tp+ fp+ fn+ tn
accuracy = (tp + tn )/(total) #round(x, 4)
precision = tp/ (tp+fp)
recall = tp/ (tp+fn)
f1 = round(1/(((1/precision) + (1/recall)) / 2), 4)
print(round(accuracy, 4))
print(round(precision, 4))
print(round(recall, 4))
print(f1)