Repository navigation
Clearer exception on legacy multi-label data representation - #13184
Merged
Merged
Conversation
Motivating example: ```python >>> from sklearn.metrics import hamming_loss >>> expt_list = [["A"], ["B"], ["C"], ["D"], ["E"], ["A", "E"]] >>> pred_list = [["A"], ["B"], ["B", "C"], ["C"], ["E"], ["A"]] >>> hamming_loss(expt_list, pred_list) Traceback (most recent call last): ... ValueError: You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead. ``` I would have found it helpful if the exception mentioned the new helper class ``MultiLabelBinarizer``, used as follows: ```python >>> from sklearn.metrics import hamming_loss >>> from sklearn.preprocessing import MultiLabelBinarizer >>> expt_list = [["A"], ["B"], ["C"], ["D"], ["E"], ["A", "E"]] >>> pred_list = [["A"], ["B"], ["B", "C"], ["C"], ["E"], ["A"]] >>> relabel = MultiLabelBinarizer(["A", "B", "C", "D", "E"]) # 5 classes >>> expt = relabel.fit_transform(expt_list) >>> pred = relabel.fit_transform(pred_list) >>> hamming_loss(expt, pred) 0.13333333333333333 ```
jnothman
approved these changes
Feb 18, 2019
Member
|
Hmmmm why is CI failing? I think you need to update tests that check for this message |
Contributor
Author
|
A pleasure, thank you both. |
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
…on (scikit-learn#13184)" This reverts commit 2ab1225.
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
…on (scikit-learn#13184)" This reverts commit 2ab1225.
koenvandevelde
pushed a commit
to koenvandevelde/scikit-learn
that referenced
this pull request
Jul 12, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
See new exception added in #4919
What does this implement/fix? Explain your changes.
Motivating example:
I would have found it helpful if the exception mentioned the new helper class
MultiLabelBinarizer, which could be used here as follows:Any other comments?
Including the helper class name makes it far easier to find documentation on the new way to do this, e.g.
https://scikit-learn.org/stable/modules/multiclass.html#multilabel-classification-format