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
FIX Support extra class_weights in compute_class_weight #22595
Merged
Merged
Conversation
This file contains 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
2 tasks
I find the behaviour a bit dangerous because you could potentially accept a key with a typo that will not be used. |
I updated the PR to be more strict when it comes to unweighted classes:
This means that an error is raised: from sklearn.tree import DecisionTreeClassifier
tree = DecisionTreeClassifier(class_weight={"dogs": 2, "cat": 1})
# Raises error
tree.fit([[1, 2, 3], [1, 3, 2]], ["dog", "cat"])
# ValueError: The classes, ['dog'], are not in class_weight |
glemaitre
reviewed
Mar 3, 2022
jjerphan
approved these changes
Mar 4, 2022
Diwakar-Gupta
pushed a commit
to Diwakar-Gupta/scikit-learn
that referenced
this issue
Mar 7, 2022
thomasjpfan
added a commit
to thomasjpfan/scikit-learn
that referenced
this issue
Mar 8, 2022
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.
Reference Issues/PRs
Fixes #22413
What does this implement/fix? Explain your changes.
This PR:
compute_class_weight
to allowclass_weight
to contain other classes that is not in theclasses
.class_weight
appear inclasses
, then an error is raised.Any other comments?
I think the intention of using
class_weights
as the source of truth is to prevent this type of error:with this PR,
"dog"
would not be weighted.