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
1
truth = [0, 1, 1, 0, 0] # Multi hot labels for one input (class 1 and 2 are present)
2
prediction = [1, 1, 1, 0, 0] # Predicted labels for the input
3
num_classes = len(truth)
4
num_samples = 1
5
โ€‹
6
numerator = float(sum(truth & prediction))
7
denominator = float(sum(truth | prediction))
8
โ€‹
9
hamming_score = numerator / denominator
Copied!

Further resources

Last modified 4mo ago