Skip to content

DEP liblinear, dual, intercept_scaling for LogisticRegression and LogisticRegressionCV - #35067

Merged
StefanieSenger merged 10 commits into
scikit-learn:mainfrom
lorentzenchr:dep_liblinear
Oct 14, 2026
Merged

StefanieSenger merged 10 commits into
scikit-learn:mainfrom
lorentzenchr:dep_liblinear

Conversation

@lorentzenchr

@lorentzenchr lorentzenchr commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Contributes to #33537.

What does this implement/fix? Explain your changes.

This PR deprecates for the classes LogisticRegression and LogisticRegressionCV:

  • solver="liblinear"
  • parameter dual as it only effects liblinear
  • parameter intercept_scaling as it only effects liblinear

AI 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:

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.

@lorentzenchr lorentzenchr added this to the 1.10 milestone Oct 4, 2026
@Higgs32584

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added CI:Linter failure The linter CI is failing on this PR and removed CI:Linter failure The linter CI is failing on this PR labels Oct 9, 2026
@Higgs32584

Copy link
Copy Markdown
Contributor

it is #35092 if you are interested. No pressure

Thank you

@OmarManzoor OmarManzoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you @lorentzenchr

Comment thread bench_logistic_reg_L1_sparse.csv Resolved
@OmarManzoor OmarManzoor added the Waiting for Second Reviewer First reviewer is done, need a second one! label Oct 12, 2026

@StefanieSenger StefanieSenger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment on lines +3506 to +3508
# 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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we remove this right now? Same on the other two newly added tests.

Suggested change
# 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")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Outdated
Comment on lines 1294 to 1295

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to already remove this and to speak about newton-cd and newton-cd-gram instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we assert this for loss="log" anymore?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lorentzenchr

Copy link
Copy Markdown
Member Author

Right now in this reproducible, we raise it 2x for LogisticRegression and 7x for LogisticRegressionCV

Well spotted. I fixed it.

@StefanieSenger StefanieSenger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you @lorentzenchr!

@StefanieSenger
StefanieSenger merged commit 9305ff8 into scikit-learn:main Oct 14, 2026
37 checks passed
@lorentzenchr

Copy link
Copy Markdown
Member Author

Wow, this was fast!!! 🚀
@ogrisel @antoinebaker fyi (we could revert if you object to this deprecation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants