Repository navigation
DEP liblinear, dual, intercept_scaling for LogisticRegression and LogisticRegressionCV - #35067
Conversation
|
Hi, I submitted a pull request relating to #31883, and I was wondering, since you are on this issue to, if you think it is the right answer or not? Thank you |
6297c7a to
c0fe4c6
Compare
|
it is #35092 if you are interested. No pressure Thank you |
OmarManzoor
left a comment
There was a problem hiding this comment.
LGTM. Thank you @lorentzenchr
and LogisticRegressionCV
bea7ae4 to
3c66c25
Compare
StefanieSenger
left a comment
There was a problem hiding this comment.
Overall, looks good to me, thank you @lorentzenchr!
There are a few suggestions, but we should also make sure we raise the solver deprecation warning only once. Right now in this reproducible, we raise it 2x for LogisticRegression and 7x for LogisticRegressionCV (for every CV-fold we re-raise it):
import warnings
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression, LogisticRegressionCV
X, y = make_classification(n_classes=2, n_samples=20, random_state=0)
for cls in (LogisticRegression, LogisticRegressionCV):
cls(solver="liblinear").fit(X, y)| # TODO(1.10): remove filter after deprecation cycle. | ||
| @pytest.mark.filterwarnings("ignore:l1_ratios parameter is only us.*:UserWarning") | ||
| @pytest.mark.filterwarnings("ignore:.*default.*use_legacy_attributes.*:FutureWarning") |
There was a problem hiding this comment.
Shouldn't we remove this right now? Same on the other two newly added tests.
| # TODO(1.10): remove filter after deprecation cycle. | |
| @pytest.mark.filterwarnings("ignore:l1_ratios parameter is only us.*:UserWarning") | |
| @pytest.mark.filterwarnings("ignore:.*default.*use_legacy_attributes.*:FutureWarning") |
There was a problem hiding this comment.
Without it, we have warnings in tests. AFAIK, we have one CI job that detects new warnings in tests.
If #35120 were merged first, I could easily remove it here.
There was a problem hiding this comment.
I would suggest to already remove this and to speak about newton-cd and newton-cd-gram instead.
There was a problem hiding this comment.
I'll just remove it. #35110 adds better information on solvers - consistently for several GLMs.
| clf.fit(X, y) | ||
| assert (np.asarray(clf.coef_) == 0).all() | ||
| assert (np.asarray(clf.intercept_) == 0).all() | ||
| if loss == "squared_hinge": |
There was a problem hiding this comment.
Why don't we assert this for loss="log" anymore?
There was a problem hiding this comment.
Liblinear always penalizes the intercept. This is bad. The remedy is to scale the intercept so as to render the penalty effect tiny for the intercept. But it is still penalized. Therefore, clf.intercept_ == 0 was true because of the particular choice of the penalty in this test (the penalty that sets all coefficients to zero).
For the LinearSVC with hinge loss, this is still true. For our modernized LogisticRegression, it is not - for good.
Well spotted. I fixed it. |
StefanieSenger
left a comment
There was a problem hiding this comment.
Great, thank you @lorentzenchr!
|
Wow, this was fast!!! 🚀 |
Reference Issues/PRs
Contributes to #33537.
What does this implement/fix? Explain your changes.
This PR deprecates for the classes
LogisticRegressionandLogisticRegressionCV:solver="liblinear"dualas it only effects liblinearintercept_scalingas it only effects liblinearAI usage disclosure
None for this PR (yet)
Any other comments?
With the new newton-cd and newton-cd-gram solvers (for L1 and ElasticNet) there is no more place where liblinear gives any advantage over other solvers. It is more the contrary, there are many issues with it:
intercept_scaling, see intercept_scaling should be set explicitly #11715.LinearSVRis not thread-safe #31883.The alternative to deprecation would be to update liblinear to its current version (we vendor a super old version with modifications). As we added modifications to the vendored version, I would advice against that.