Skip to content

MNT carry out 1.10 deprecations in LogisticRegression - #35120

Merged
virchan merged 12 commits into
scikit-learn:mainfrom
lorentzenchr:mnt_logreg_depr_110
Oct 30, 2026
Merged

virchan merged 12 commits into
scikit-learn:mainfrom
lorentzenchr:mnt_logreg_depr_110

Conversation

@lorentzenchr

Copy link
Copy Markdown
Member

Reference Issues/PRs

See below

What does this implement/fix? Explain your changes.

AI usage disclosure

I used AI assistance for:

  • Research and understanding

Any other comments?

It's 4 clean commits. I can also split this PR into 4 PRs.

@lorentzenchr

Copy link
Copy Markdown
Member Author

@jeremiedbb @virchan If it is sound and safe to assume that there won't be a 1.9.2, we could merge this one.

@virchan virchan 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.

Comment thread sklearn/linear_model/_logistic.py Resolved
@github-actions

Copy link
Copy Markdown

This PR exceeds the recommended size of 500 lines changed. Consider splitting it into smaller PRs to ease the review process. Please make sure you read our Contributing guide and in particular our Pull Request guidelines

@virchan virchan 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.

Thank you for updating the PR, @lorentzenchr. Here is the next round of review.

  1. We can remove these filters:
# 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")

The l1_ratios warning no longer exists after this PR; and the use_legacy_attributes warning only fires when the parameter is explicitly passed, which these tests do not.

There are three of them: 1, 2, 3.

  1. The doc-string here should read:
"was deprecated in version 1.10 and will be removed in 1.12"

similar to #35120 (comment).

@virchan virchan 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.

Apologies for the noise. I have a few more comments on test_logistic.py.

Additionally, asv_benchmarks/benchmarks/linear_model.py needs to be updated. This isn't covered by CI; and it will fail after this PR, because LogisticRegression no longer accepts n_jobs.

Specifically, we need to:

  1. Remove n_jobs from param_names and params:

class LogisticRegressionBenchmark(Predictor, Estimator, Benchmark):
"""
Benchmarks for LogisticRegression.
"""
param_names = ["representation", "solver", "n_jobs"]
params = (["dense", "sparse"], ["lbfgs", "saga"], Benchmark.n_jobs_vals)

  1. Update the parameter unpacking in these locations:

def make_data(self, params):
representation, solver, n_jobs = params

def make_estimator(self, params):
representation, solver, n_jobs = params

  1. Remove n_jobs from LogisticRegression:

estimator = LogisticRegression(
solver=solver,
l1_ratio=l1_ratio,
tol=0.01,
n_jobs=n_jobs,
random_state=0,
)

We also need a changelog entry for the deprecation of use_legacy_attributes, which begins with this PR.

Otherwise, the PR LGTM, and I'm happy to approve once these are addressed.

@StefanieSenger StefanieSenger added this to the 1.10 milestone Oct 21, 2026
@lorentzenchr

lorentzenchr commented Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

We also need a changelog entry for the deprecation of use_legacy_attributes, which begins with this PR.

We already have from #32114.
But ok, I‘ll add another one.

@lorentzenchr

Copy link
Copy Markdown
Member Author

@virchan ready to merge imo.

@virchan virchan 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.

Thank you for updating the PR, @lorentzenchr. I have a few more suggestions for the changelog and doc-string.

I would also like to revisit our discussion on removing the C-warning filter: #35120 (comment).

I agree that we should avoid unrelated clean-ups in this PR.

Previously, the test passed C=np.inf, so suppressing the C warning was appropriate. This PR changes that to alpha=0 and renames the test, leaving the warning dead.

That's why I consider removing the filter to be within the scope of this PR.

That said, I'm approving this PR, assuming the suggestions on changelog and doc-string get applied. Removing the C filter is non-blocking, so I'm happy either way.

Comment thread sklearn/linear_model/_logistic.py Resolved
@virchan virchan added the Waiting for Second Reviewer First reviewer is done, need a second one! label Oct 24, 2026
@virchan

virchan commented Oct 24, 2026

Copy link
Copy Markdown
Member

@jeremiedbb, would you like to have a look?

@cakedev0 cakedev0 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.

Thanks for the PR, it's always pleasant to see the number of lines go down.

AI and I found a few small things, but they should be easy to fix/resolve.

Comment thread sklearn/linear_model/_logistic.py Resolved
See also parameter `use_legacy_attributes`.

scores_ : dict or ndarray of shape (n_folds, n_l1_ratios, n_alphas)
scores_ : dict or ndarray of shape (n_folds, n_alphas, n_l1_ratios)

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.

With use_legacy_attributes=False by default, scores_ is an ndarray of shape (n_folds, n_l1_ratios, n_alphas) (I get (5, 1, 10) with default params), so this change makes the header wrong for the default. Same for:

  • coefs_paths_: documented as a dict, now an ndarray of shape (n_folds, n_l1_ratios, n_alphas, n_classes, n_dof) (with 1 instead of n_classes for binary problems)
  • C_ and l1_ratio_: documented as ndarrays of shape (n_classes,), now floats
  • n_iter_: documented as (1, n_folds, n_alphas, n_l1_ratios), now (n_folds, n_l1_ratios, n_alphas)

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 did not change that yet because it seems easier to me to do that once use_legacy… is removed abd we don’t need to document both versions.

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.

Ok, trusting your judgement on this one 👍

Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
@lorentzenchr

Copy link
Copy Markdown
Member Author

IMO, ready to merge.

Comment thread sklearn/linear_model/_logistic.py Resolved

@cakedev0 cakedev0 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.

LGTM, I think we can merge indeed.

@virchan virchan 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.

Thank you everyone for your time!

Merging.

@virchan
virchan merged commit 360f3eb into scikit-learn:main Oct 30, 2026
37 of 38 checks passed
@lorentzenchr

Copy link
Copy Markdown
Member Author

This was one of the largest deprecations I‘ve done (but not each one stems from me). Thanks to all reviewers!

@lorentzenchr
lorentzenchr deleted the mnt_logreg_depr_110 branch October 30, 2026 17:42
rapids-bot Bot pushed a commit to NVIDIA/cuml that referenced this pull request Nov 4, 2026
…o` export in `as_sklearn()` (#8855)

scikit-learn/scikit-learn#35120 removed `LogisticRegression.penalty` (deprecated since 1.8). `_params_from_cpu`
reads `model.penalty` without a guard, so with the sklearn nightly every `cuml.accel` LogisticRegression fit and every
`LogisticRegression.from_sklearn` raises:

```
AttributeError: 'LogisticRegression' object has no attribute 'penalty'
```

For example nightly run https://github.com/NVIDIA/cuml/actions/runs/41593489373

While fixing that, I found a bug in the export direction that already affects released scikit-learn 1.8 and 1.9.
`_params_to_cpu` translates cuML's `penalty` into an `l1_ratio`, but it looked the dict up with `self.l1_ratio`
instead of `self.penalty`. Fixed in this PR as well. Reproduced with sklearn 1.9.1:

| cuML model | `as_sklearn()` before | refit by sklearn |
|---|---|---|
| `penalty="l2"` (default) | `l1_ratio=0.0` | correct |
| `penalty="l1"` | `l1_ratio=0.0` | fits with a L2 penalty |
| `penalty="elasticnet", l1_ratio=0.5` | `l1_ratio=None` | fits with L2 penalty and a `FutureWarning`/an error on 1.10 |
| `penalty=None` | `l1_ratio=0.0, C=inf` | correct |

I added an explicit test of these combinations and assert on what should happen (`test_logistic_regression_penalty_roundtrip`).

Now `python/cuml/cuml/linear_model/logistic_regression.py` takes care of making things "canonical" and fixes the case of using `l1_ratio` to perform the look up.

The "make things canonical" change changes behaviour for `cuml.accel` and `from_sklearn` on sklearn >= 1.8:
  - `LogisticRegression(l1_ratio=1)` now imports as `penalty="l1"`, where before it was `"elasticnet"` with
    `l1_ratio=1` (mathematically this is equivalent)
  - `C=inf` / `alpha=0` now imports as `penalty=None, C=1.0`, where before it was `"l2"` with `C=inf`. I think the math maths the same but it feels more explicit to set the penalty to `None` and leave C set to the default value.

But this makes the roundtripping work. Worth it I think.


Closes #8854

Authors:
  - Tim Head (https://github.com/betatim)

Approvers:
  - Simon Adorf (https://github.com/csadorf)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants