Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-095

Jaccard Index

Problem

Compute the Jaccard index (intersection over union) for binary labels with positive class 1: TP / (TP + FP + FN).

Return 0.0 when the denominator is zero or the input is empty.

Hint

Intersection over union of the predicted and true positive sets.

Test cases

case 1
in: [[1,0,1,1],[1,0,0,1]]
expected: 0.6666666666666666
case 2
in: [[1,1,0,0],[1,1,0,0]]
expected: 1
case 3
in: [[1,0],[0,1]]
expected: 0
case 4
in: [[],[]]
expected: 0
Starter codePython
def jaccard_index(y_true, y_pred):
    # Your code here
    pass

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