Repository navigation
DEP deprecate LogisticRegression parameters C, introduce new regularization parameter alpha - #32042
Conversation
…new regularization parameter alpha
|
This PR is intentionally not yet 100% implemented (class weights, LogisticRegressionCV, fixing a lot of tests elsewhere, etc.). Let's first see how the discussion goes. |
|
I'm +1 on using That said, I haven’t fully considered the engineering cost of completing this 😅. At first glance, we would also need to update the A few examples would also need updating (e.g., |
…ce new regularization parameter alphas * default of l1_ratio from None to 0.0
82ee1ca to
e0cdfdb
Compare
|
I have several worries about this change:
I seriously doubt that the benefits in clarity and API consistency outweighs those costs, even if integrated over the expected lifetime of the scikit-learn project. The third point could be addressed by defining an |
|
🤔 I opened #28711 in March 2024 over a year ago, @scikit-learn/core-devs were pinged. Yet, it did not receive any critical or worried voices. So thanks @ogrisel for raising them now.
Good point that I did not consider so far. Just my conclusion is different: It gives the authors the opportunity to publish a new edition. Considering all the big API changes that we had (metadata routing, pandas in/out, array api), it seems like this change of penalty param of LogisticRegression would be very minor. This is also a point that could be raised with any deprecation. Fortunately, we don't. Then as analogy, old material of C++ before C++11 is also very outdated. You should not learn from it. Better learn modern C++, so at least C++17.
Isn't it the case with any deprecation? Just that LogisticRegression might be among the most used classes we have. We could spend an extended deprecation period, e.g. 4 instead of 2 releases.
Have a look at the table in #28711 (comment). LogisticRegression is really outstanding in being the only one not having alpha as its penalty parameter. As a maintainer, this makes my brain itch every time I see it. As current main developer for linear models, I see it very often. Also literature prefers penalty instead of anti-penalty C, e.g. the legendary Elements of Statistical Learning and the original publication for penalized (ridge) logreg Cessie (1992) https://doi.org/10.2307/2347628. I guess the C-variant mainly stems from SVM-literature. SVMs nowadays are very much outdated. |
|
The deprecation of Regarding
There are 2 changes in the PR that should be discussed separately imo:
|
|
I add #32659 to have the deprecation of There are a lot of deprecation in LR going on. I think we should not miss this window and also decide for the deprecation of @scikit-learn/core-devs @scikit-learn/documentation-team @scikit-learn/communication-team ping |
|
To me C -> alpha feels like a scikit-learn 2.0 kind of change. If we decide to do it, which I am slightly against right now to be honest, it's certainly not something I would rush because the 1.8 release is approaching. |
|
I personally have an easier time thinking in |
|
I just want to mention the fact that in today's LLM-assisted coding, API changes are even costlier than before.
Let me expand a bit: when someone uses an LLM assistant like copilot (and many many people do), it generates based on the code lines that it has seen in the past. And here existing volumes of code win: the more an LLM has seen a pattern, a group of code tokens, the more likely it is to generate it.
So, LLMs generate code based on previous APIs. This is not hypothetical; for scikit-learn, copilot keeps generating OneHotEncoder(sparse=False), while these days it is OneHotEncoder(sparse_output=False).
Changing API is now costlier, because beginner coders/data-scientist think that they can go faster by generating large chunks of code for LLMs, and then the code doesn't run, and they are lost.
We should weigh these decisions very carefully.
Sorry, I did not bring this to the discussion earlier, because I only realize the cost of this behavior to some users just recently.
|
|
Let me add a few points in favor of the proposed change:
|
|
I'm not sure I have a strong opinion either way here. As a maintainer I'm weary of (big) deprecations because it causes some code churn and extra issues opened from users who are unhappy that something changed in the universe. I can also see the advantage of a more consistent API across estimators and being more aligned with text books. I looked at the Yes, books and other material will need updating. Have we got a precedent where we renamed a prominent constructor argument? How did it go that time? Something that is not clear to me is related to (c) in Olivier's comment: is So I guess my impression is: definitely maybe? (We do have lots of nots in the API doc about stuff that was added/changed in 0.x - maybe time to clean that up?) |
left a comment
There was a problem hiding this comment.
I'm happy with the responses to my comments. It seems we have consensus to merge this but a few people said they wanted to/were going to review this. Should we wait for you? Is it ok for you to review it after it has been merged and we make follow up PRs with fixes? There is time between now and the next release of 1.10 for fixes to get merged.
| With this change the penalty parameter of most linear models is `alpha`, the larger | ||
| its value the stronger the penalty. For L2-penalties, the parametrization is | ||
| similar to :class:`linear_model.Ridge` where the penalty gets weaker the larger the | ||
| training dataset (by a factor of `1/n_samples`). |
There was a problem hiding this comment.
Maybe we should say that this behavior is not new?
There was a problem hiding this comment.
Do you have a suggestion. It speaks more about Ridge which was not changed.
commented
Oct 1, 2026
via email
|
For LogisticRegressionCV, descending alphas is faster to fit. And this is a test. I would leave it as is.
Point taken
|
commented
Oct 5, 2026
|
Ready to merge? Anyone? |
commented
Oct 6, 2026
|
I am reviewing it at the moment. |
| With this change the penalty parameter of most linear models is `alpha`, the larger | ||
| its value the stronger the penalty. For L2-penalties, the parametrization is | ||
| similar to :class:`linear_model.Ridge` where the penalty gets weaker the larger the | ||
| training dataset (by a factor of `1/n_samples`). |
There was a problem hiding this comment.
Adding a "now" helps make it explicit that Logistic Regression is now aligned to Ridge (and that Ridge hasn't changed).
| With this change the penalty parameter of most linear models is `alpha`, the larger | |
| its value the stronger the penalty. For L2-penalties, the parametrization is | |
| similar to :class:`linear_model.Ridge` where the penalty gets weaker the larger the | |
| training dataset (by a factor of `1/n_samples`). | |
| With this change the penalty parameter of most linear models is `alpha`, the larger | |
| its value the stronger the penalty. For L2-penalties, the parametrization is | |
| now similar to :class:`linear_model.Ridge` where the penalty gets weaker the | |
| larger the training dataset (by a factor of `1/n_samples`). |
There was a problem hiding this comment.
But it is the same (similar to Ridge) as before, larger sample size -> weaker penalty. Gael wanted to change in the opposite direction, mentioning that this is nothing new.
As we discussed the scaling with n_samples extensively, I thought it a good idea to mention the analogy with Ridge. I would keep it as is as a statement of facts (neither "new" nor "unchanged").
commented
Oct 8, 2026
|
This PR has now 3 approvals and I addressed all review comments as good as I could. |
|
I want to say thank you to all the participants, especially the reviewers and final approvals and to @betatim for finally merging this PR! |
commented
Oct 9, 2026
|
If we had named it |
commented
Oct 9, 2026
via email
|
and it's friday night ;)
Message ID: ***@***.***>
glad to see this finally coming to an end with a consensus from the
team 🎉🍾
|
|
Hello, this is the "CI is broken" annoying person again 😝. The doc build is broken on main because a couple of the examples still use
Relevant info from build logAnd since @agramfort is here (👋 by the way) a private joke from the (good?) old days 🤪.
|
commented
Oct 10, 2026
|
CI is green again, all good, thanks @virchan! And just to state the "obvious" explicitly (in case I get in trouble with the CoC one day 😅), #32042 (comment) was tongue in cheek, nobody is going to die for a red CI 🤪. |

Reference Issues/PRs
Closes #28711.
Related to #11865.
Update June 2026 (scikit-learn sprint)
Update August 2026 with #32042 (comment)
What does this implement/fix? Explain your changes.
This PR
LogisticRegressionCin 1.10Cin 1.14alphasets defaultalpha="1/n_samples"such that it is the same asC=1alpha=1which is equivalent toC=1LogisticRegressionCVCsalphasC_andCs_in 1.10, removal in 1.14alpha_andalphas_Details
NOTE: This "details" contains the outdate/old content.
Update March 2026 after merge of #32659.
What does this implement/fix? Explain your changes.
This PR
LogisticRegressionCalphadeprecates the parameterpenaltychanges the default ofl1_ratiofromNoneto0LogisticRegressionCVCsalphasC_andCs_alpha_andalphas_deprecates parameterpenaltychanges the default ofl1_ratiosfromNoneto(0,)StackingClassifierfinal_estimator=Nonewhich usesLogisticRegression()Update August 2026 see #32042 (comment):
The scaling of the penalty is chosen with minimum change:
alpha = 1/CLogisticRegressionis then aligned withRidgeLogisticRegressionpenaltyalphais then different fromSGDClassifier(alpha=.., loss="log_loss")(despite of Lasso(alpha) = SGDRegressor(alpha, penalty="l1"), but Ridge(alpha) = SGDRegressor(alpha / len(train_set)) #21891 and LogisticRegression's regularization is scaled by the dataset size #30308)ElasticNet(alpha=.., l1_ratio=..)Lasso(alpha=)PoissonRegressor(alpha=)For historians, the parameter
scale_Cwhich devidedCbyn_sampleswas once deprecated in #821.Details
Note: This is outdated content as of August 2026
Note: Together with #32659, the way to specify penalties is then 100% aligned with
SGDClassifier(alpha=.., loss="log_loss")(this is even the identical model!), see Lasso(alpha) = SGDRegressor(alpha, penalty="l1"), but Ridge(alpha) = SGDRegressor(alpha / len(train_set)) #21891ElasticNet(alpha=.., l1_ratio=..)Lasso(alpha=)PoissonRegressor(alpha=)All use
1/(2n) * sum(deviance loss) + alpha/2 * ||w||_2. See #15657 for further reasons of this choice.Details
NOTE: This is outdated content.
Open questions
Default
alphaWhile the future default is currently
alpha=1, a much smaller value might be better in practice, e.g. alpha=1e-4. Tiny regularization is also the main effect ofC=1as it scales the penalty by 1/n_samples.For optimal prediction$p=P(Y|X)$ , the expected log loss is the Shannon entropy (up to a factor) $E[log loss] = H(p) = -p \log(p) - (1-p)\log(1-p)$ . The maximum is achieved at p=0.5 with H=0.69, some more values: H(1e-3) = 0.007, H(1e-6) = 1.5e-5. This shows, that
alpha=1is a pretty strong penalty (for features of scale 1 or smaller).Depending on the default of
alpha, a good default forStackingClassifier(final_estimator=..)is basically no or tiny regularization.Any other comments?
This will be a highly controversial issue, therefore a lot of fun ahead 🎉
Details
Outdated content
The main reason for this change is that the current API is objectively bad design.
Currently, I need to specify 3 parameters (penalty,C,l1_ratio) for just 2 effective parameters (the L1 and L2 penalization). On top, it warns a lot when mixing those, e.g.penalty="l2"andl1_ratio=0, but why on earth...More arguments for
alphainstead ofCC, all the others use penaltyalpha, see RFC New parameters for penalties in LogisticRegression #28711 (comment).alpha) and not an anti-penalty (likeC). The papers for Lasso & Elastic-Net in combination with logreg do the same (use penalty likealpha).alpha, they call itlambda, but that does not work in Python) and not an anti-penalty (likeC).alpha) version can be seen as regularization to prevent singular behaviour (analogous to Levenberg-Marquardt algorithm), see Nocedal.Cvs.alphain LogisticRegression in 2993bec. My guess is that liblinear's parameter names were just inherited.C=0(alpha=np.inf), butC=np.inf(alpha=0) is used very often. Zero is a much better defined value than infinity.Cinterferes with class weights. Higher class weights means less regularization.C(and IFAIC its origin) is the analogy with support vector machines. SVM were once very powerful, but have become less and less important in practice. My prediction: this trend will continue.Study of possible default values for the penalty
See #32042 (comment) and the linked notebook https://github.com/lorentzenchr/notebooks/blob/master/logistic_regression_optimal_penalty.ipynb.