Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-404

F1 from Precision Recall

Problem

The F1 score is the harmonic mean of precision and recall: 2 p r / (p + r). Return 0.0 when both are zero.

Given precision and recall, return F1.

Hint

Both metrics must be good for F1 to be high.

Test cases

case 1
in: [0.8,0.6]
expected: 0.6857142857142857
case 2
in: [1,1]
expected: 1
case 3
in: [0.5,0]
expected: 0
Starter codePython
def f1_from_precision_recall(precision, recall):
    # Your code here
    pass

3 test cases · run your code against them in the editor