Compute the average Hamming loss.
The Hamming loss is the fraction of labels that are incorrectly predicted.
Read more in the User Guide.
Ground truth (correct) labels.
Predicted labels, as returned by a classifier.
Sample weights.
Added in version 0.18.
Return the average Hamming loss between element of y_true
and y_pred
.
See also
accuracy_score
Compute the accuracy score. By default, the function will return the fraction of correct predictions divided by the total number of predictions.
jaccard_score
Compute the Jaccard similarity coefficient score.
zero_one_loss
Compute the Zero-one classification loss. By default, the function will return the percentage of imperfectly predicted subsets.
Notes
In multiclass classification, the Hamming loss corresponds to the Hamming distance between y_true
and y_pred
which is equivalent to the subset zero_one_loss
function, when normalize
parameter is set to True.
In multilabel classification, the Hamming loss is different from the subset zero-one loss. The zero-one loss considers the entire set of labels for a given sample incorrect if it does not entirely match the true set of labels. Hamming loss is more forgiving in that it penalizes only the individual labels.
The Hamming loss is upperbounded by the subset zero-one loss, when normalize
parameter is set to True. It is always between 0 and 1, lower being better.
References
[1]Grigorios Tsoumakas, Ioannis Katakis. Multi-Label Classification: An Overview. International Journal of Data Warehousing & Mining, 3(3), 1-13, July-September 2007.
Examples
>>> from sklearn.metrics import hamming_loss >>> y_pred = [1, 2, 3, 4] >>> y_true = [2, 2, 3, 4] >>> hamming_loss(y_true, y_pred) 0.25
In the multilabel case with binary label indicators:
>>> import numpy as np >>> hamming_loss(np.array([[0, 1], [1, 1]]), np.zeros((2, 2))) 0.75
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4