Repository navigation
MNT carry out 1.10 deprecations in LogisticRegression - #35120
Conversation
84ac53b to
5986ca7
Compare
4e4b30c to
e0c6945
Compare
e0c6945 to
5e04264
Compare
5e04264 to
2a7b7bf
Compare
|
@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
left a comment
There was a problem hiding this comment.
Thank you for the PR, @lorentzenchr. Here is the first round of review that I did with AI:
-
This part is repeated, and we should remove it: https://github.com/lorentzenchr/scikit-learn/blob/2a7b7bfb38f62c113491496a49548ef9b928374a/sklearn/linear_model/_logistic.py#L1497-L1498
-
The filter can be removed here: https://github.com/lorentzenchr/scikit-learn/blob/2a7b7bfb38f62c113491496a49548ef9b928374a/sklearn/linear_model/tests/test_logistic.py#L272-L273. Because we never passed
use_legacy_attributesto the test. Hence, the warning never fired.
2a7b7bf to
75a0b3c
Compare
|
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
left a comment
There was a problem hiding this comment.
Thank you for updating the PR, @lorentzenchr. Here is the next round of review.
- 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.
- The doc-string here should read:
"was deprecated in version 1.10 and will be removed in 1.12"similar to #35120 (comment).
virchan
left a comment
There was a problem hiding this comment.
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:
- Remove
n_jobsfromparam_namesandparams:
scikit-learn/asv_benchmarks/benchmarks/linear_model.py
Lines 20 to 26 in 1065739
- Update the parameter unpacking in these locations:
scikit-learn/asv_benchmarks/benchmarks/linear_model.py
Lines 31 to 32 in 1065739
scikit-learn/asv_benchmarks/benchmarks/linear_model.py
Lines 47 to 48 in 1065739
- Remove
n_jobsfromLogisticRegression:
scikit-learn/asv_benchmarks/benchmarks/linear_model.py
Lines 52 to 58 in 1065739
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.
We already have from #32114. |
75a0b3c to
58932ad
Compare
58932ad to
f127d37
Compare
|
@virchan ready to merge imo. |
virchan
left a comment
There was a problem hiding this comment.
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.
|
@jeremiedbb, would you like to have a look? |
cakedev0
left a comment
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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 ofn_classesfor binary problems)C_andl1_ratio_: documented as ndarrays of shape(n_classes,), now floatsn_iter_: documented as(1, n_folds, n_alphas, n_l1_ratios), now(n_folds, n_l1_ratios, n_alphas)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ok, trusting your judgement on this one 👍
8ee354e to
0e0e3c9
Compare
|
IMO, ready to merge. |
cakedev0
left a comment
There was a problem hiding this comment.
LGTM, I think we can merge indeed.
virchan
left a comment
There was a problem hiding this comment.
Thank you everyone for your time!
Merging.
|
This was one of the largest deprecations I‘ve done (but not each one stems from me). Thanks to all reviewers! |
…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
Reference Issues/PRs
See below
What does this implement/fix? Explain your changes.
penaltyinLogisticRegressionandLogisticRegressionCV, see DEP parameter penalty in LogisticRegression and LogisticRegressionCV #32659l1_ratiosto(0,)inLogisticRegressionCV, see DEP parameter penalty in LogisticRegression and LogisticRegressionCV #32659n_jobsinLogisticRegression, see MNT Deprecate n_jobs in LogisticRegression #32742use_legacy_attributestoFalseand deprecate it, see DEP start deprecation of attributes in LogisticRegressionCV #32114AI usage disclosure
I used AI assistance for:
Any other comments?
It's 4 clean commits. I can also split this PR into 4 PRs.