All problems
F1 Score from Counts
Problem
Return the F1 score from true positives tp, false positives fp, and false negatives fn: 2*tp / (2*tp + fp + fn). Return 0.0 when the denominator is zero.
Hint
It is the harmonic mean of precision and recall.
Test cases
case 1
in: [5,1,2]
expected: 0.7692307692307693
case 2
in: [0,0,0]
expected: 0
case 3
in: [3,0,0]
expected: 1
case 4
in: [1,0,1]
expected: 0.6666666666666666
case 5
in: [4,1,0]
expected: 0.8888888888888888
Starter codePython
def f1_score(tp, fp, fn):
# Your code here
pass5 test cases · run your code against them in the editor