-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] FIX+TST regression in multinomial logstc reg when class_weight is auto #5420
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
There are still Using two variables that only differ by capitalization does not seem like a very good idea... |
It appears that the usage is intended (though I am not sure why we need to have the variable named I think we can safely rename |
@@ -875,3 +875,11 @@ def test_warm_start(): | |||
assert_greater(2.0, cum_diff, msg) | |||
else: | |||
assert_greater(cum_diff, 2.0, msg) | |||
|
|||
|
|||
@ignore_warnings |
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.
why ignore the warnings? which warnings are raised in that case?
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.
auto
is deprecated in favor of balanced
? In that case put a please use assert_warns
to make it expliclit that we expect a DeprecationWarning
.
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.
Warning that auto
will no longer be supported!
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.
okay will do so :)
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.
Is it me or is 'balanced' and 'auto' are treated the same, see: this line where the check is against 'balanced' and not 'auto'.
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.
check seems to against auto only?
if class_weight == "auto":
class_weight_ = compute_class_weight(class_weight, mask_classes,
y_bin)
sample_weight *= class_weight_[le.fit_transform(y_bin)]
Do you mean some other line? sorry I don't get what you are saying!
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.
check seems to against auto only?
sorry I meant against 'auto' and not 'balanced', just as you said.
be44403
to
a17b70b
Compare
Or should I do that in this PR itself? (renaming |
The rule is |
Actually it's not a rule but a convention in the scikit-learn code base. Although it's not always respected it's better to follow it for consistency. |
Ah thanks for clarifying!! :) |
why is there a deprecation here? |
Or rather: does this work correctly with "balanced"? |
I guess merge this and open a new issue? |
I don't think 'auto' and 'balanced' give the same result: from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
X, y = make_classification(n_classes=5, n_informative=5, random_state=42)
model_auto = LogisticRegression(multi_class='multinomial', class_weight='auto',
solver='lbfgs', random_state=0)
model_auto.fit(X, y)
model_balanced = LogisticRegression(multi_class='multinomial', class_weight='balanced',
solver='lbfgs', random_state=0)
model_balanced.fit(X, y)
print(model_auto.coef_ - model_balanced.coef_) Output:
|
see #5422 |
That's a good question. I would rather check that before merging. And add a test if there is no test for that case. |
@lesteve they are not supposed to give the same result. But having special treatment for one and not the other seems fishy |
This is expected. This is why we deprecated 'auto'. The results are not what people would naively expect. It was a misleading sklearn specific heuristic. 'balanced' implements the industry standard. |
OK sorry for the noise and thanks for the details. |
The fix is to do |
|
Can you remove the if and see if it passes after the fix I suggested above? |
I tried and it doesn't pass...! |
Also I'm surprised by the behavior of |
The idea is that in In We do not do model averaging, the comment in that sense is slightly wrong (unless refit is set to False). It should be |
Ah, I overlooked the refit parameter. But that negates the argument, right? The final |
Just a second. Trying out something. |
Actually I do get the same coefs :| |
If |
The fix looks good to me though. (It was working before, I think it somehow broke while adding the |
why is the value of C found different if the parameters are the same? |
Because the parameters for every fold are not the same. Minimal code to reproduce
Note that the first one chooses a C of 0.359 while the second chooses a C of 0.0001 (np argmax chooses the first C). This leads to differences in the final fit. |
Sorry I introduced this bug in this commit 94eb619#diff-1452d97adf1a0b794930e405aa58d64bR613 It should be solved in #5008 |
I agree. |
have to look more closely at #5008, not sure I have time for that today. For the failing test, we could just search over a single C [or maybe better two very far apart Cs]. |
I changed this behavior in # 5008. |
I am closing this in favour of #5008 which fixes a few more issues which were raised here by @amueller @MechCoder and others... |
Fixes #5415
@lesteve @MechCoder Please review!