Hamming Score

Metric for Accuracy of Multi Label Multi Class Prediction

Hamming Score is the fraction of correct predictions compared to the total labels. This is similar to Accuracy, and in fact they are interchangeable.

Hamming Score is simply Accuracy

Code implementation

hamming_score.py
truth = [0, 1, 1, 0, 0] # Multi hot labels for one input (class 1 and 2 are present)
prediction = [1, 1, 1, 0, 0] # Predicted labels for the input
num_classes = len(truth)
num_samples = 1
numerator = float(sum(truth & prediction))
denominator = float(sum(truth | prediction))
hamming_score = numerator / denominator

Further resources