Skip to content

[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

Conversation

XavierSATTLER
Copy link
Contributor

Reference Issues/PRs

Fixes #13734

What does this implement/fix? Explain your changes.

This issue started because of a typo in hamming loss docstrings:

The Hamming loss is upperbounded by the subset zero-one loss. When normalized over samples, the Hamming loss is always between 0 and 1.

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.

@XavierSATTLER XavierSATTLER changed the title Xavier sattler/doc/hamming loss 13734 [DOC] clarified hamming loss docstrings May 1, 2019
@@ -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.
Copy link
Member

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?

Copy link
Contributor Author

@XavierSATTLER XavierSATTLER May 5, 2019

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.

Copy link
Member

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

@jnothman jnothman merged commit 0caf914 into scikit-learn:master May 8, 2019
@jnothman
Copy link
Member

jnothman commented May 8, 2019

Thanks @XavierSATTLER

jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request May 8, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unclear when hamming loss is normalized and when not
3 participants