Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-176

Hamming Loss

Problem

Compute the Hamming loss for a multilabel matrix: the fraction of entries where y_true and y_pred disagree.

Empty input returns 0.0.

Hint

Count all mismatched label entries and divide by the total number of entries.

Test cases

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

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