All problems
Dice Coefficient for Binary Labels
Problem
Compute the Dice coefficient for binary labels with positive class 1: 2*TP / (2*TP + FP + FN).
Return 0.0 when the denominator is zero or the input is empty.
Hint
The Dice coefficient is the F1 score of the positive class.
Test cases
case 1
in: [[1,0,1,1],[1,0,0,1]]
expected: 0.8
case 2
in: [[1,1,0,0],[1,1,0,0]]
expected: 1
case 3
in: [[1,1],[0,0]]
expected: 0
case 4
in: [[],[]]
expected: 0
Starter codePython
def dice_coefficient(y_true, y_pred):
# Your code here
pass4 test cases · run your code against them in the editor