-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG] Added penalty='none' to LogisticRegression #12860
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
sklearn/linear_model/logistic.py
Outdated
Used to specify the norm used in the penalization. The 'newton-cg', | ||
'sag' and 'lbfgs' solvers support only l2 penalties. 'elasticnet' is | ||
only supported by the 'saga' solver. | ||
only supported by the 'saga' solver. If 'none' (not supported by the | ||
liblinear solver), no regularization is applied: this 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.
Perhaps don't bother stating the equivalence here? There is enough to read
sklearn/linear_model/logistic.py
Outdated
@@ -1705,10 +1731,12 @@ class LogisticRegressionCV(LogisticRegression, BaseEstimator, | |||
l2 penalty with liblinear solver. Prefer dual=False when | |||
n_samples > n_features. | |||
|
|||
penalty : str, 'l1', 'l2', or 'elasticnet', optional (default='l2') | |||
penalty : str, 'l1', 'l2', 'elasticnet' or 'none', optional (default='l2') |
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.
What's the point of supporting none in CV, when its role is to determine the optimal C under cross-validation?
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.
Good point, I was in auto pilot ^^
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.
Please test the error msg in LRCV(penalty='none'). Ideally, mention that 'none' is not useful w/ LRCV
sklearn/linear_model/logistic.py
Outdated
only supported by the 'saga' solver. If 'none' (not supported by the | ||
liblinear solver), no regularization is applied: this is equivalent | ||
to setting C to ``np.inf`` with 'l2'. | ||
only supported by the 'saga' solver. |
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.
Perhaps note that 'none' is not useful with LogisticRegressionCV?
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!
doc/whats_new/v0.21.rst
Outdated
@@ -88,6 +88,12 @@ Support for Python 3.4 and below has been officially dropped. | |||
:class:`linear_model.LogisticRegressionCV` now support Elastic-Net penalty, | |||
with the 'saga' solver. :issue:`11646` by :user:`Nicolas Hug <NicolasHug>`. | |||
|
|||
- |Feature| :class:`linear_model.LogisticRegression` now supports an |
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 suspect that since we're not adding any new functionality, this should strictly be an enhancement.
Thanks! |
Reference Issues/PRs
Closes #6738
What does this implement/fix? Explain your changes.
Support 'none' for
penalty
inLogisticRegerssion
which is equivalent to settingpenalty='l2'
andC=np.inf
.This is supported by all solvers except liblinear which seems to take forever even on small datasets. For the other solvers, I haven't observed any significant change (in fit time or score) by using
C=np.inf
instead of the default value (see plots)Any other comments?
Benchmarks on my laptop (8Go RAM, i5 7th gen) showing logloss and fit time in seconds, averaged over 10 experiments:
setting C to np.inf:
setting C to default value:
I don't know if I did something wrong but the docs say that sag should be faster for large datasets while lbfgs should be slower, but I'm observing the reverse.