-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[DOC] clarified hamming loss docstrings #13760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DOC] clarified hamming loss docstrings #13760
Conversation
sklearn/metrics/classification.py
Outdated
@@ -1989,16 +1989,16 @@ def hamming_loss(y_true, y_pred, labels=None, sample_weight=None): | |||
----- | |||
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. | |||
subset ``zero_one_loss`` function, when zero-one loss is normalized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean by normalized. The zero-one loss is either 0 or 1. Maybe you mean averaged over samples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi !
Please correct me if I'm wrong. I think zero-one loss is either 0 or 1 for a sample, but we are talking about a subset (so a batch) of samples here. In this case, one has two choices. One can sum the losses of the samples, or take what I would call a "normalized sum", which is the sum rescaled to be 0 if all samples are right and 1 if they are all wrong.
I use the name "normalized sum" because in sklearn.metrics.zero_one_loss, you can choose the second behaviour by setting the normalize
parameter to True. It will be a simple sum if normalize
is False.
To my understanding, the fact that this "normalized sum" is equal to the average over samples is a simple consequence of zero-one loss being 0 or 1 (so it is a consequence, not a property, which is why I am not so comfortable with the use of "average over samples").
The clarification I want to make in the documentation is that in multiclass classification, hamming loss is equivalent to zero-one loss if and only if zero-one loss is in its "normalized" form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking simply at the diff it was not clear that you were referring to the "normalize" parameter of the function. Can you maybe just clarify that it refers to the normalize parameter. Then looking at normalize parameter it's clearer what it means. thanks
Thanks @XavierSATTLER |
Reference Issues/PRs
Fixes #13734
What does this implement/fix? Explain your changes.
This issue started because of a typo in hamming loss docstrings:
It made it believe that the Hamming loss had to be normalized. In fact, it is the zero-one loss that has to be normalized to be able to compare it with Hamming loss.
I then saw an other typo in the multilabel classification paragraph, and added few words to make the documentation clearer.