In multilabel classification, each sample can belong to multiple classes simultaneously, and predictions are typically represented as binary indicator matrices of shape (n_samples, n_labels). The Hamming loss measures the fraction of label assignments that are incorrectly predicted across the entire matrix.
Implement hamming_loss(y_true, y_pred) that:
y_true and y_pred as 2D lists or numpy arrays of the same shape (n_samples, n_labels) with binary entries (0 or 1).float equal to the average per-label mismatch rate over the entire matrix.n_samples == 0 or n_labels == 0), returns 0.0.The two arrays are guaranteed to have matching shapes.