-
-
Notifications
You must be signed in to change notification settings - Fork 26.4k
DEP parameter penalty in LogisticRegression and LogisticRegressionCV #32659
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
base: main
Are you sure you want to change the base?
DEP parameter penalty in LogisticRegression and LogisticRegressionCV #32659
Conversation
ogrisel
left a comment
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.
Thanks for getting this is in. I just have a concern with the warning strategy for l1_ratios in LogisticRegressionCV (see below).
sklearn/linear_model/_logistic.py
Outdated
| _raise_for_params(params, self, "fit") | ||
|
|
||
| solver = _check_solver(self.solver, self.penalty, self.dual) | ||
| if isinstance(self.l1_ratios, str) and self.l1_ratios == "warn": |
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.
Are we sure we want to warn by default? I would expect LogisticRegressionCV(Cs=np.logspace(-6, 6, 13)).fit(X_train, y_train) to behave the same in 1.10 and 1.8, and so I don't see the point in warning the user when using the default. The only behavioral change would be sklearn.get_params()["l1_ratios"] which would change from None to (0.0,). I don't know we if we should consider a worse breaking change than from None to "warn".
I think we should only warn when the user explicitly passes LogisticRegressionCV(Cs=np.logspace(-6, 6, 13), l1_ratios=None).fit(X_train, y_train) instead.
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.
In that case, same as l1_ratio for LogisticRegression. I will add the changes accordingly.
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'm easy either way, but generally speaking, we don't have the policy of things not warning when using default values. In many cases, the user has to set something to silence the warning.
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.
At first, I thought so, too. In this particular case, the behavioral change ist almost none such that a „hard“ change of the default value without warning period seems justified.
As I demonstrated, I can implement either way (simply reverting eab936a eould be enough to switch).
I am rather indifferent to the possibilities, just say which one:
In any case, |
doc/whats_new/upcoming_changes/sklearn.linear_model/32659.api.rst
Outdated
Show resolved
Hide resolved
sklearn/linear_model/_logistic.py
Outdated
| l1_ratio : float, default=0.0 | ||
| The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only | ||
| used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent |
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 got a bit surprised with the "only used if penalty='elasticnet'".
Could we move it at the end of the paragraph instead and mention that l1_ratio has an effect with penalty is let as its default or that one force penalty="elasticnet" (but it is deprecated).
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 changed a bit more, see c745f77 .
| is_logreg_l1_penalized = est_name == "LogisticRegression" and ( | ||
| hasattr(estimator, "l1_ratio") and np.isclose(estimator.l1_ratio, 1.0) | ||
| ) | ||
| is_logregcv_l1_penalized = est_name == "LogisticRegressionCV" and ( | ||
| hasattr(estimator, "l1_ratio_") | ||
| and np.all(np.isclose(estimator.l1_ratio_, 1.0)) | ||
| ) |
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.
Those are not used I think.
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.
Now with b3b50fa they are used.
glemaitre
left a comment
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.
LGTM. Only 3 tiny changes.
Reference Issues/PRs
Partially solves #28711.
This is the the no-brainer of #32042 (comment).
What does this implement/fix? Explain your changes.
This PR
deprecates the parameters penalty
changes the default of l1_ratio from None to 0
deprecates the parameters penalty
changes the default of l1_ratios from None to (0,)
Any other comments?