Skip to content

Fix for Multiclass SVC.fit fails if sample_weight zeros out a class #26593

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

Closed

Conversation

rand0wn
Copy link
Contributor

@rand0wn rand0wn commented Jun 15, 2023

Reference Issues/PRs

Fixes #25380

What does this implement/fix? Explain your changes.

Fix for multiclass SVM when weights of a class are zero

Now it removes the class with zero weights from X, y, and sample_weight
Trains the model and skips zero classes

Also, a test to assert model params when it is trained with or without the class

A new warning for removing the weights has been added

Any other comments?

The labels of y remain unchanged

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in terms of API, regardless of whether a class is zeroed out, it should be included in classes_, the same way it is for other cases (dense, LinearSVC, etc)

To be consistent, the fix needs to be in svm.cpp, the same way it's done for the other case, which you see around this line:

fprintf(stderr,"warning: class label %d specified in weight is not found\n", param->weight_label[i]);

It's not gonna be easy 😁

@@ -144,7 +143,6 @@ def _more_tags(self):
# Used by cross_val_score.
return {"pairwise": self.kernel == "precomputed"}

@_fit_context(prefer_skip_nested_validation=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an unintended change, should be put back

Comment on lines +179 to +180
self._validate_params()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, should be removed

@glemaitre glemaitre self-requested a review November 9, 2023 16:48
@glemaitre
Copy link
Member

Closing this PR because it does not seem to be the right fix: #25380 (comment)

@glemaitre glemaitre closed this Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SVC and OneClassSVM fails to fit or have wrong fitted attributes with null sample weights
3 participants