Skip to content

DEP deprecate LogisticRegression parameters C, introduce new regularization parameter alpha - #32042

Merged
betatim merged 66 commits into
scikit-learn:mainfrom
lorentzenchr:logistic_penalty_alpha
Oct 9, 2026
Merged

betatim merged 66 commits into
scikit-learn:mainfrom
lorentzenchr:logistic_penalty_alpha

Conversation

@lorentzenchr

@lorentzenchr lorentzenchr commented Aug 28, 2025 •

Copy link
Copy Markdown
Member

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

  • for class LogisticRegression
    • deprecates parameter C in 1.10
      • will raise warning in 1.12
      • will remove C in 1.14
    • introduces the new penalty parameter alpha
    • sets default alpha="1/n_samples" such that it is the same as C=1
    • sets default alpha=1 which is equivalent to C=1
  • for class LogisticRegressionCV
    • deprecates the parameter Cs
    • introduces the new penalty parameter alphas
    • deprecates attributes C_ and Cs_ in 1.10, removal in 1.14
    • introduces new attributes alpha_ and alphas_
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

  • for class LogisticRegression
    • deprecates parameter C
    • introduces the new penalty parameter alpha
    • deprecates the parameter penalty
    • changes the default of l1_ratio from None to 0
  • for class LogisticRegressionCV
    • deprecates the parameter Cs
    • introduces the new penalty parameter alphas
    • deprecates attributes C_ and Cs_
    • introduces new attributes alpha_ and alphas_
    • deprecates parameter penalty
    • changes the default of l1_ratios from None to (0,)
  • for class StackingClassifier
    • Additional informative warning for default final_estimator=None which uses LogisticRegression()

Update August 2026 see #32042 (comment):
The scaling of the penalty is chosen with minimum change:

For historians, the parameter scale_C which devided C by n_samples was 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

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

  1. Default alpha
    While 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 of C=1 as 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=1 is a pretty strong penalty (for features of scale 1 or smaller).

  2. Depending on the default of alpha, a good default for StackingClassifier(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" and l1_ratio=0, but why on earth...

More arguments for alpha instead of C

  1. API consistency: LogisticRegression is the only linear model using an anti-penalty C, all the others use penalty alpha, see RFC New parameters for penalties in LogisticRegression #28711 (comment).
  2. Literature:
  1. Other reference packages: The most famous R package glmnet (and others) uses a penalty (like alpha, they call it lambda, but that does not work in Python) and not an anti-penalty (like C).
  2. Point of view of optimization: the penalty (like alpha) version can be seen as regularization to prevent singular behaviour (analogous to Levenberg-Marquardt algorithm), see Nocedal.
  3. Original decision and discussion: I cannot find any discussion about the original introduction of C vs. alpha in LogisticRegression in 2993bec. My guess is that liblinear's parameter names were just inherited.
  4. Practicality: One never needs C=0 (alpha=np.inf), but C=np.inf (alpha=0) is used very often. Zero is a much better defined value than infinity.
  5. C interferes with class weights. Higher class weights means less regularization.
  6. The main reason for 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.

@github-actions

github-actions Bot commented Aug 28, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

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

Generated for commit: e0cdfdb. Link to the linter CI: here

@lorentzenchr

lorentzenchr commented Aug 28, 2025 •

Copy link
Copy Markdown
Member Author

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.

@lorentzenchr lorentzenchr added the Needs Decision Requires decision label Aug 28, 2025
@virchan

virchan commented Aug 29, 2025

Copy link
Copy Markdown
Member

I'm +1 on using alpha over C in LogisticRegression so the regularisation parameter is coherent with Lasso and Ridge.

That said, I haven’t fully considered the engineering cost of completing this 😅. At first glance, we would also need to update the l1_min_c function and, as a result, the support vector machines.

A few examples would also need updating (e.g., plot_logistic_l1_l2_sparsity.py and plot_logistic_path.py). That should be relatively easy, though, since I already have an ongoing PR #30028 updating examples on the regularisation of linear models. If we decide to move forward with this change for LogisticRegression, I can help with the documentation part.

@lorentzenchr lorentzenchr changed the title MNT deprecate LogisticRegression parameters penalty and C, introduce new regularization parameter alpha DEP deprecate LogisticRegression parameters penalty and C, introduce new regularization parameter alpha Aug 31, 2025
@lorentzenchr
lorentzenchr force-pushed the logistic_penalty_alpha branch from 82ee1ca to e0cdfdb Compare August 31, 2025 09:13
@ogrisel

ogrisel commented Sep 2, 2025 •

Copy link
Copy Markdown
Member

I have several worries about this change:

  • a) there is a lot of published education material that will become obsolete. Updating that will induce a significant cost and will not always be possible (e.g. printed books, recorded video tutorials...);
  • b) this change will induce significant cost in updating third-party code bases. This is hard to quantify.
  • c) I have the impression the default C=1. led to models with reasonably good cross-validation performance (even if not guaranteed to be optimal in any way). I suspect that this won't be the case for the new alpha=1. default parametrization. We would need to conduct some evaluation to check if this intuition can be backed by empirical results, and if such, what would be the probability of getting very bad models with the new default compared to the current C=1. default parametrization.

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 alpha="auto" default policy that would set the value of alpha at fit time in a way that is equivalent to using the current C=1. default value. That would also help address parts of concern a) and b) for all code and resources that use the default value of the hyper-parameter.

@lorentzenchr

Copy link
Copy Markdown
Member Author

🤔 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.

a) there is a lot of published education material that will become obsolete. Updating that will induce a significant cost and will not always be possible (e.g. printed books);

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.

b) this change will induce significant cost in updating third-party code bases. This is hard to quantify.

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.

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.

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.

@jeremiedbb

Copy link
Copy Markdown
Member

The deprecation of penalty is a no brainer to me. It's just redundant.

Regarding C, it's less obvious but I think I'm +1 to replace by a penalization alpha. I agree with Olivier's first 2 points, but it also has advantages. For instance I believe that it's less confusing for newcomers if all linear model implement penalization the same way. From the perspective of our own doc and api, it's an improvement.

c) I have the impression the default C=1. led to models with reasonably good cross-validation performance (even if not guaranteed to be optimal in any way). I suspect that this won't be the case for the new alpha=1. default parametrization. We would need to conduct some evaluation to check if this intuition can be backed by empirical results, and if such, what would be the probability of getting very bad models with the new default compared to the current C=1. default parametrization.

There are 2 changes in the PR that should be discussed separately imo:

  • C -> 1/alpha. Then the default alpha=1 is equivalent to the default C=1. It can almost be seen as a renaming.
  • normalize the penalization term by the sum of sample weights. This is a change of behavior that is not easy to compensate in user's code. It could deserve its own issue + PR. For instance Lasso doesn't have this normalization.

@lorentzenchr

Copy link
Copy Markdown
Member Author

I add #32659 to have the deprecation of penalty separated.

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 C and introduction of alpha in the 1.8 release.

@scikit-learn/core-devs @scikit-learn/documentation-team @scikit-learn/communication-team ping

@lesteve

lesteve commented Nov 6, 2025 •

Copy link
Copy Markdown
Member

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.

@adrinjalali

Copy link
Copy Markdown
Member

I personally have an easier time thinking in C rather than alpha, just because I've mostly ran all my experiments back in the day with C, and I can imagine that's true for a lot of people. However, thinking in C and passing 1/C as an arg is also pretty easy to do. So I'm abstaining here.

@GaelVaroquaux

GaelVaroquaux commented Nov 6, 2025 via email

Copy link
Copy Markdown
Member

@lorentzenchr

Copy link
Copy Markdown
Member Author

Let me add a few points in favor of the proposed change:

  1. API consistency: LogisticRegression is the only linear model using an anti-penalty C, all the others use penalty alpha, see RFC New parameters for penalties in LogisticRegression #28711 (comment).
  2. Literature:
  1. Other reference packages: The most famous R package glmnet uses a penalty (like alpha) and not an anti-penalty (like C).
  2. Point of view of optimization: the penalty (like alpha) version can be seen as regularization to prevent singular behaviour (analogous to Levenberg-Marquardt algorithm), see Nocedal.
  3. Original decision and discussion: I cannot find any discussion about the original introduction of C vs. alpha in LogisticRegression in 2993bec. My guess is that liblinear's parameter names were just used.
  4. Practicality: One never needs C=0 (alpha=np.inf), but C=np.inf (alpha=0) is used very often. Zero is a much better defined value than infinity.

@betatim

betatim commented Nov 13, 2025

Copy link
Copy Markdown
Member

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 LogisticRegression API doc half expecting to see a warning/note about how "C does not work the way you think it will. It is the inverse!" but all I could find is a short comment about it. Also in the user guide there isn't much about it. Sometimes what is/isn't in the docs is a sign for what confuses people.

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 alpha exactly equal to 1/C or is it proportional to alpha? A nice feature of C is that you can keep your HP search space (and intuition) fixed no matter how many samples (or sample weights) you have. If alpha = 1/C this isn't an issue, if there is a scaling factor related to n_samples (or weights) then that makes alpha harder to think about for the average person on the data-science highway.

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?)

ghost 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'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.

ghost 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'm sending right now a review that I started to do earlier this week but didn't have time to finish as early feedback

Comment thread doc/modules/model_evaluation.rst Resolved
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`).

ghost Sep 28, 2026

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.

Maybe we should say that this behavior is not new?

ghost Oct 1, 2026

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.

Do you have a suggestion. It speaks more about Ridge which was not changed.

Comment thread examples/compose/plot_digits_pipe.py Resolved
@GaelVaroquaux

ghost commented Oct 1, 2026 via email

Copy link
Copy Markdown
Member

@lorentzenchr

ghost commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

Ready to merge? Anyone?

@ogrisel

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Member

I am reviewing it at the moment.

ghost 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.

A few small suggestions but otherwise LGTM.

Comment thread sklearn/linear_model/_logistic.py Resolved
Comment on lines +17 to +20
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`).

ghost Oct 7, 2026

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.

Adding a "now" helps make it explicit that Logistic Regression is now aligned to Ridge (and that Ridge hasn't changed).

Suggested change
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`).

ghost Oct 7, 2026 •

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.

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").

@lorentzenchr

ghost commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

This PR has now 3 approvals and I addressed all review comments as good as I could.
As it is custom in scikit-learn, it is one of the reviewers who merges. May I kindly ask one of you to "have the honor"?

@betatim
betatim merged commit 5eacafa into scikit-learn:main Oct 9, 2026
@lorentzenchr

ghost commented Oct 9, 2026 •

Copy link
Copy Markdown
Member Author

I want to say thank you to all the participants, especially the reviewers and final approvals and to @betatim for finally merging this PR!
This took a lot of energy, but I am convinced that it has a positive net effect and it gives us a good story to tell: Now all linear models (except for OrthogonalMatchingPursuit) have penalty alpha!

@lorentzenchr
lorentzenchr deleted the logistic_penalty_alpha branch October 9, 2026 11:49
@betatim

ghost commented Oct 9, 2026

Copy link
Copy Markdown
Member

If we had named it beta I would have merged it even more eagerly ;)

@agramfort

ghost commented Oct 9, 2026 via email

Copy link
Copy Markdown
Member

@lesteve

ghost commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

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 C I guess?

  • examples/calibration/plot_calibration_multiclass.py
  • examples/applications/plot_face_recognition.py
Relevant info from build log
    Unexpected failing examples (2):
    
        ../examples/calibration/plot_calibration_multiclass.py failed leaving traceback:
    
        Traceback (most recent call last):
          File "/home/circleci/project/examples/calibration/plot_calibration_multiclass.py", line 358, in <module>
            base_clf.fit(X_train, y_train)
            ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
          File "/home/circleci/project/sklearn/base.py", line 1403, in wrapper
            return fit_method(estimator, *args, **kwargs)
          File "/home/circleci/project/sklearn/pipeline.py", line 652, in fit
            self._final_estimator.fit(Xt, y, **last_step_params["fit"])
            ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/circleci/project/sklearn/base.py", line 1403, in wrapper
            return fit_method(estimator, *args, **kwargs)
          File "/home/circleci/project/sklearn/linear_model/_logistic.py", line 1525, in fit
            warnings.warn(depr_msg, FutureWarning)
            ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
        FutureWarning: 'C' was deprecated in version 1.10 and will be removed in 1.14. Use alpha instead. Note that setting the new parameter alpha=1/C gives the same results as the old C. You can avoid this warning by setting alpha and leaving C to its default.
    
        ../examples/applications/plot_face_recognition.py failed leaving traceback:
    
        Traceback (most recent call last):
          File "/home/circleci/project/examples/applications/plot_face_recognition.py", line 133, in <module>
            clf = clf.fit(X_train, y_train)
          File "/home/circleci/project/sklearn/base.py", line 1403, in wrapper
            return fit_method(estimator, *args, **kwargs)
          File "/home/circleci/project/sklearn/model_selection/_search_successive_halving.py", line 270, in fit
            super().fit(X, y=y, **params)
            ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
          File "/home/circleci/project/sklearn/base.py", line 1403, in wrapper
            return fit_method(estimator, *args, **kwargs)
          File "/home/circleci/project/sklearn/model_selection/_search.py", line 1132, in fit
            self._run_search(evaluate_candidates, callback_ctx=root_callback_ctx)
            ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/circleci/project/sklearn/model_selection/_search_successive_halving.py", line 395, in _run_search
            results = evaluate_candidates(
                candidate_params,
            ...<2 lines>...
                callback_ctx=iteration_callback_ctx,
            )
          File "/home/circleci/project/sklearn/model_selection/_search.py", line 1108, in evaluate_candidates
            _warn_or_raise_about_fit_failures(out, self.error_score)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/circleci/project/sklearn/model_selection/_validation.py", line 470, in _warn_or_raise_about_fit_failures
            raise ValueError(all_fits_failed_message)
        ValueError: 
        All the 150 fits failed.
        It is very likely that your model is misconfigured.
        You can try to debug the error by setting error_score='raise'.
    
        Below are more details about the failures:
        --------------------------------------------------------------------------------
        150 fits failed with the following error:
        Traceback (most recent call last):
          File "/home/circleci/project/sklearn/model_selection/_validation.py", line 831, in _fit_and_score
            estimator.fit(X_train, y_train, **fit_params)
            ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/circleci/project/sklearn/base.py", line 1403, in wrapper
            return fit_method(estimator, *args, **kwargs)
          File "/home/circleci/project/sklearn/pipeline.py", line 652, in fit
            self._final_estimator.fit(Xt, y, **last_step_params["fit"])
            ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/circleci/project/sklearn/base.py", line 1403, in wrapper
            return fit_method(estimator, *args, **kwargs)
          File "/home/circleci/project/sklearn/linear_model/_logistic.py", line 1525, in fit
            warnings.warn(depr_msg, FutureWarning)
            ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
        FutureWarning: 'C' was deprecated in version 1.10 and will be removed in 1.14. Use alpha instead. Note that setting the new parameter alpha=1/C gives the same results as the old C. You can avoid this warning by setting alpha and leaving C to its default.

And since @agramfort is here (👋 by the way) a private joke from the (good?) old days 🤪.

image

@lorentzenchr

ghost commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

ironie: It seems people have been eager to be faster introducing code with C than I was able to remove it. Evidence: 4 months ago #34247 and 2 weeks ago #34313 (this one even merged by me)

@lesteve

ghost commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

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 🤪.

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

Labels

High Priority High priority issues and pull requests module:linear_model

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC New parameters for penalties in LogisticRegression