Hamming score

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

Python


python
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

Get AI confident. Start using Hasty today.

Our platform is completely free to try. Sign up today to start your two-month trial.