-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG+1] use class_weight through sample_weight in LogisticRegression with liblinear #6817
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
"solver cannot handle multiclass with " | ||
"class_weight of type dict. Use the lbfgs, " | ||
"newton-cg or sag solvers or set " | ||
"class_weight='balanced'") |
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.
this is not true anymore?
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.
No, since liblinear solver handles sample_weight
(#5274), we can make the behavior identical for all LogisticRegression
's solvers, by merging the class_weight
into the sample_weight
.
+1 for merge |
for class_weight in ({0: 0.1, 1: 0.2, 2: 0.5}, 'balanced'): | ||
for n_classes in [3, 2]: | ||
if n_classes == 2 and class_weight != 'balanced': | ||
class_weight.pop(2) |
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.
to avoid bugs if this were extended, can we please do class_weight = class_weight.copy()
first?
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 have changed the loops to avoid modifications on class_weight
.
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 have changed the loops to avoid modifications on class_weight.
Yes, of course that's the sensible way to do it!
Otherwise, LGTM |
2c33e39
to
c640fce
Compare
would you like to add to |
c640fce
to
1107f22
Compare
Done. I also added |
Let's do it. |
I forgot to update #5008 after we merged #5274 (cf. #5008 (comment)).
It makes the
class_weight
behavior consistent with all solver ofLogisticRegression
, by putting theclass_weight
into thesample_weight
.Fixes #6795