Skip to content

MNT clean-up deprecations for 1.7: multi_class in LogisticRegression#31241

Merged
lorentzenchr merged 12 commits into
scikit-learn:mainfrom
jeremiedbb:logistic-multiclass-liblinear
May 5, 2025
Merged

MNT clean-up deprecations for 1.7: multi_class in LogisticRegression#31241
lorentzenchr merged 12 commits into
scikit-learn:mainfrom
jeremiedbb:logistic-multiclass-liblinear

Conversation

@jeremiedbb

@jeremiedbb jeremiedbb commented Apr 22, 2025

Copy link
Copy Markdown
Member

When cleaning-up the deprecation of the multi_class parameter, see #28703, I found that we haven't been raising a warning the last 2 versions for the following situation:

from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression

iris = load_iris()

# multiclass problem with solver="liblinear" and multi_class left to default
LogisticRegression(solver="liblinear").fit(iris.data, iris.target)

In this setting it falls back to OVR because liblinear doesn't support multinomial. However the deprecation of multi_class implied that all multiclass problems would be fitted using the multinomial loss and that an error would be raised if a solver doesn't support it. See

From then on, the recommended 'multinomial' will always be used for `n_classes >= 3`.
Solvers that do not support 'multinomial' will raise an error.
Use `sklearn.multiclass.OneVsRestClassifier(LogisticRegression())` if you still want to use OvR.

That's an issue because doing it for 1.7 would break code that was working until now without any FutureWarning.

A pragmatic solution is to delay the deprecation clean-up and raise a warning for this specific case for 1 more release (I don't think we really need 2 here). This is what I implemented in this PR. What do you think @lorentzenchr @ogrisel ?
Do you think it's worth a new specific changelog entry ? I feel like the one in v1.5.rst is enough.

@jeremiedbb jeremiedbb added this to the 1.7 milestone Apr 22, 2025
@github-actions

github-actions Bot commented Apr 22, 2025

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 519b315. Link to the linter CI: here

@lorentzenchr

Copy link
Copy Markdown
Member

First of all, sorry for this mistake.

I would actually dare to carry out the deprecation in 1.7 and see if anybody complains. I have heard so many complaints about scikit-learn, but never about deprecations and their settlement .

@jeremiedbb

Copy link
Copy Markdown
Member Author

First of all, sorry for this mistake.

Well I think I reviewed your PR so we share it :)

I have heard so many complaints about scikit-learn, but never about deprecations and their settlement .

Maybe because we're cautious about backward compatibility and because we take care to break their code without notice 😉

I would actually dare to carry out the deprecation in 1.7 and see if anybody complains

It crossed my mind, but I think it's better to do the right thing. It could be a pain for some users while keeping the deprecated code 1 more release for us is not an major issue (it might delay some refactorings in logistic regression if planned though).
Let's see what @ogrisel and @adrinjalali think. If needed, I have a branch with the full clean-up ready 😄 .

thomasjpfan
thomasjpfan previously approved these changes Apr 24, 2025

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

I prefer this PR's approach of raising a deprecation warning first.

Let's also include a changelog entry. One cycle for a deprecation warning is shorter than normal.

@thomasjpfan thomasjpfan dismissed their stale review April 24, 2025 16:11

We should still add to changelog so people know about it. One cycle for a deprecation warning is shorter than normal.

@jeremiedbb

Copy link
Copy Markdown
Member Author

Let's also include a changelog entry

Done

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

@jeremiedbb It seems I forgot to update the solver table in the docstring of LogisticRegression: newton-cholesky now supports multiclass!!!
Could you update that here?

Comment thread sklearn/metrics/_ranking.py Outdated
Comment thread sklearn/metrics/_ranking.py Outdated

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

@jeremiedbb thanks

@pras529

pras529 commented Jul 20, 2025

Copy link
Copy Markdown
Contributor

@jeremiedbb please review this minor documentation correction.

stratakis added a commit to stratakis/sklearn-genetic that referenced this pull request Aug 4, 2025
On scikit-learn >= 1.7, using  the liblinear solver for multiclass
classification with a one-versus-rest (ovr) scheme is deprecated.

See: scikit-learn/scikit-learn#31241
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants