Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-094

F-Beta Score

Problem

Compute the F-beta score: (1 + beta^2) * precision * recall / (beta^2 * precision + recall), where precision = TP/(TP+FP) and recall = TP/(TP+FN) and both are 0.0 when their denominator is zero.

Return 0.0 if the F-beta denominator is 0. Empty input returns 0.0.

Hint

beta > 1 favors recall; beta < 1 favors precision; beta = 1 is the harmonic mean of the two.

Test cases

case 1
in: [[1,0,1,1,0],[1,0,0,1,0],1]
expected: 0.8
case 2
in: [[1,0,1,1,0],[1,0,0,1,0],2]
expected: 0.7142857142857142
case 3
in: [[1,0,1,1,0],[1,0,0,1,0],0.5]
expected: 0.9090909090909091
case 4
in: [[0,0],[1,1],1]
expected: 0
case 5
in: [[],[],1]
expected: 0
Starter codePython
def fbeta_score(y_true, y_pred, beta):
    # Your code here
    pass

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