Skip to content

DOC more precise calibration wording #28171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 23, 2024

Conversation

GaelVaroquaux
Copy link
Member

A logistic regression will return well-calibrated predictions only if it is well specified. Some people were interpreting our text out of context and over-generalizing the sentence saying the a log-reg returns well-calibrated predictions.

Here is a minor modification to make it more precise

A logistic regression will return well-calibrated predictions only if it
is well specified. Some people were interpreting our text out of context
and over-generalizing the sentence saying the a log-reg returns
well-calibrated predictions.

Here is a minor modification to make it more precise
Copy link

github-actions bot commented Jan 18, 2024

✔️ Linting Passed

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

Generated for commit: 074f08f. Link to the linter CI: here

Copy link
Member

@ArturoAmorQ ArturoAmorQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a tweak, otherwise LGTM :) Thanks @GaelVaroquaux, this certainly improves the wording!

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the suggested improvement.

Note that the level of regularization (and the presence of uninformative features in the low sample size regime) can also strongly impact the over-/under-confidence in predictions by
logistic regression models.

I plan to expand an example in the future to demonstrate this empirically but maybe in the short term we could just expand the paragraph as in the following suggestion.

But if you think that renders the paragraph too verbose, we can leave this for later. The current state of this PR is already a net improvement.

@ogrisel
Copy link
Member

ogrisel commented Jan 18, 2024

/cc @lorentzenchr

@@ -74,10 +74,12 @@ by showing the number of samples in each predicted probability bin.

.. currentmodule:: sklearn.linear_model

:class:`LogisticRegression` returns well calibrated predictions by default as it has a
:class:`LogisticRegression` is more likely to return well calibrated predictions by default as it has a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"more likely" calls for a comparison: more likely than what?

I would also like to change the term "by default" to something better. Maybe "by itself", "without re-calibration, or "if well specified"

GaelVaroquaux and others added 3 commits January 18, 2024 22:49
Co-authored-by: Arturo Amor <86408019+ArturoAmorQ@users.noreply.github.com>
Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
Merge suggested wordings from @lorentzenchr and @ogrisel
@@ -74,10 +74,14 @@ by showing the number of samples in each predicted probability bin.

.. currentmodule:: sklearn.linear_model

:class:`LogisticRegression` returns well calibrated predictions by default as it has a
:class:`LogisticRegression` is more likely to return well calibrated predictions by itself as it has a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to address @lorentzenchr's comment:

Suggested change
:class:`LogisticRegression` is more likely to return well calibrated predictions by itself as it has a
:class:`LogisticRegression` is likely to return well calibrated predictions by itself as it has a

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not: some people are going to argue that it's not that likely in absolute

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another pass of suggestion after iterating on the example itself (see details below):

@ogrisel
Copy link
Member

ogrisel commented Jan 24, 2024

@GaelVaroquaux @lorentzenchr @ArturoAmorQ if you all agree with the suggestions in the comments above I can take care of applying this them all into this PR and rewrap the resulting paragraphs to get a clean diff.

@glemaitre glemaitre added this to the 1.4.1 milestone Feb 6, 2024
@lorentzenchr
Copy link
Member

Superseded by #28231

@ArturoAmorQ
Copy link
Member

ArturoAmorQ commented Feb 22, 2024

@lorentzenchr not sure we wanted to close this one as it concerns the user guide, whereas #28231 targets the Comparison of Calibration of Classifiers example.

@GaelVaroquaux GaelVaroquaux reopened this Feb 22, 2024
@GaelVaroquaux
Copy link
Member Author

I agree that this addresses a complementary aspect than #28231 and I think this needs to be merged.

I must say that I got a bit tired by the back and forth of nitpick on wordings that are somewhat at odds with the fact that the original wording is overall not great and that, IMHO, this was an improvement.

@ogrisel
Copy link
Member

ogrisel commented Feb 22, 2024

@lorentzenchr not sure we wanted to close this one as it concerns the user guide, whereas #28231 targets the Comparison of Calibration of Classifiers example.

Exactly, my objective in opening #28231 was:

  • to fix the figure used in the user guide (because previously it did not really show a well calibrated curve for LR, contradicting the message).
  • and improve its analysis w.r.t. what I understood based on the discussion in this PR.

Still I think we should still fix the user guide to merge this PR possibly as is (as it's already a net improvement to mention well-specification which is a very important condition to get well-calibrated LR models.

If you agree, I would be willing to put some further efforts to refine this section in a follow-up PR.

@GaelVaroquaux
Copy link
Member Author

GaelVaroquaux commented Feb 22, 2024 via email

Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
@lorentzenchr
Copy link
Member

So for closing too prematurely. But the net result is good. This PR moves forward.

@ogrisel
Copy link
Member

ogrisel commented Feb 23, 2024

So shall we merge? My +1 still holds.

This leads to the so-called **balance property**, see [8]_ and
:ref:`Logistic_regression`.
In the unpenalized case, this leads to the so-called **balance property**, see [8]_ and :ref:`Logistic_regression`.
In the plot above, data is generated according to a linear mechanism, which is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogrisel Can you comment if this is true?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably dependent on the random seed but it's probably not too false, otherwise the calibration curve would be bad. I would rather keep the message simple enough in the user guide for now and refine the example(s) iteratively in follow-up PRs and update the user guide accordingly once this is done.

Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
@lorentzenchr lorentzenchr changed the title DOC: more precise calibration wording DOC more precise calibration wording Feb 23, 2024
@lorentzenchr lorentzenchr enabled auto-merge (squash) February 23, 2024 14:21
@lorentzenchr lorentzenchr merged commit fe718a8 into scikit-learn:main Feb 23, 2024
@ogrisel
Copy link
Member

ogrisel commented Feb 23, 2024

Thanks all. I will try to open a follow-up issue / PR soon.

@GaelVaroquaux
Copy link
Member Author

GaelVaroquaux commented Feb 23, 2024 via email

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.

5 participants