Skip to content

DOC fix calibration user guide and references - #34289

Merged
betatim merged 5 commits into
scikit-learn:mainfrom
lorentzenchr:doc_calibration_references
Jul 27, 2026
Merged

betatim merged 5 commits into
scikit-learn:mainfrom
lorentzenchr:doc_calibration_references

Conversation

@lorentzenchr

Copy link
Copy Markdown
Member

Reference Issues/PRs

Follow-up/Oversight of #33856.

What does this implement/fix? Explain your changes.

This PR improves the user guide on n_bins in calibration curve a bit. In particular, it removes the references.

If we want a reference, we should use more original ones, for examples:

AI usage disclosure

None

Any other comments?

@lorentzenchr

Copy link
Copy Markdown
Member Author

@ogrisel @antoinebaker @ZeyuSun fyi

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Jun 13, 2026
@ogrisel

ogrisel commented Jun 15, 2026

Copy link
Copy Markdown
Member

I think we should keep the references that show the n ** (1/3) rule is asymptotically suitable for the specific problem of calibration curve estimation. As discussed in #33856 (comment) (and above) it is not obvious to me at all that why the optimal rules for setting the number of bins for density estimation with histograms (where x is the domain of the "target" random variable of interest and y is the density of that same variable) and calibration curve estimation with binning (where x is the domain of a continuous conditioning random variable and y is the expected value of the conditional expectation) are the same.

Digging a bit more about this, I think the name for this second problem seems to be "regressograms" rather than "histograms".

  • Wassermann "All of Statistics" Chapter 20 "Nonparametric Curve Estimation" seems to only mention the rule of n ** (1/3) in case of histograms, not for regressograms.

  • Scott "Multivariate Density Estimation" also seems to focus of histograms and I cannot find a discussion of the case of conditional expectation estimation.

I will try to dig a bit further to find if there are earlier proofs for n ** (1/3) rule for the particular case of conditional expectation estimation via binning (aka regressograms).

@lorentzenchr

Copy link
Copy Markdown
Member Author

@ogrisel Those 2 are just the wrong references to cite because they are not the first ones (eg Dimitriadis is 2 years esrlier), and I don’t want scikit-learn to provide them with citation counts.
Therefore, this PR just removes those references (anticipating controversial about what to cite).

Please not again an endless discussion!

@lorentzenchr

Copy link
Copy Markdown
Member Author

@antoinebaker What‘s your opinion?

@lorentzenchr

Copy link
Copy Markdown
Member Author

@ogrisel We have an estimator called "histogram gradient boosting", the histograms bin features and sum up gradients and hessians.

The main point is that I merged the other PR and I should not have done. But I wanted to unblock further development.

Maybe @lucyleeow or @betatim can help here.

@antoinebaker

antoinebaker commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

I think the references to the textbooks (Wassermann or Scott) are too generic, and would require the user to dig in and see the connection with computing the calibration error or estimating the calibration curve.

The two cited papers Sun et al Futmani et al are precisely on the topic of the calibration error bias and optimal number of bins, the first reference even has figure 2 to check that the optimal number of bins follows a cube root rule. I think it's good to provide the user with a straightforward reference.

It's true that the justification for the cube root rule for the number of bins appears in the Appendix B of [
Dimitriadis et al, and here it's discussed for the CEP estimates (ie how close the points computed by calibration_curve are to the true curve). So I feel that's a good reference to add.

TDLR: I would personally be in favor of something like:

When `n_bins="cube_root"`, the number of
bins is automatically set to :math:`\lceil n_{\text{samples}}^{1/3} \rceil`,
which aims this balance this trade-off, leading to a better estimation of the calibration 
curve [Dimitriadis et al], as well as the calibration error [Sun et al].

EDIT: maybe the [Sun et al] reference belongs more to the brier_calibration_error tackled in #34261. That is we keep [Dimitriadis et al] for the calibration curve , and [Sun et al] for the calibration error. WDYT ?

@lorentzenchr

Copy link
Copy Markdown
Member Author

Thanks @antoinebaker. I added the Dimitriadis reference as you suggested.

@ogrisel

ogrisel commented Jun 16, 2026

Copy link
Copy Markdown
Member

Thanks @antoinebaker. I added the Dimitriadis reference as you suggested.

@antoinebaker did not suggest removing Sun et al nor Futmani et al though.

@ogrisel

ogrisel commented Jun 16, 2026

Copy link
Copy Markdown
Member

EDIT: maybe the [Sun et al] reference belongs more to the brier_calibration_error tackled in #34261. That is we keep [Dimitriadis et al] for the calibration curve , and [Sun et al] for the calibration error. WDYT ?

I think the two are related. I would use the same references for the cube-root rules for all of them.

@ogrisel

ogrisel commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

I digged further, and I found that the optimal cube-root number of bins from the histogram literature (Scott 1979) can indeed be adapted to equal-width regressograms and therefore equal-width binned calibration curves as show in the proof of theorem 7.1 of those lecture notes https://faculty.washington.edu/yenchic/24A_stat535/Lec7_NPregression.pdf The proof was added in 2025 and previous versions of those lecture notes had no proof.

The lecture notes refer to All of Nonparametric Statistics by Larry Wasserman but I cannot find this proof there: section 5.2 covers regressograms but without the result on the optimal number of bins and histograms are covered in section 6. The link between the two is not that explicit.

Furthermore, the proof in the lecture notes is non-trivial, this is not a peer-reviewed paper and this does not cover the equal-mass binning result (Sun et al precisely consider equal-mass binning case).

So to me Sun et al and Futmani et al still deserve to be legitimately referenced here.

EDIT: actually there is a weakness in the proof of the lecture notes:

Similarly, one can show that M · μ_M (x) can be viewed as an estimator of μ(x)
and μ(x) − M · μM (x) = O(1/M).

M · μ_M (x) is not a histogram of μ(x) because μ(x) is not a density function so the O(1/M) bias result requires extra assumption.

@lorentzenchr

lorentzenchr commented Jun 16, 2026 •

Copy link
Copy Markdown
Member Author

So to me Sun et al and Futmani et al still deserve to be legitimately referenced here.

I disagree. The proof with histograms more or less carries over 1-1 to "regressograms" (or whatever they are called), $P(Y|X=x)$ and binning of $x$ instead of just $P(Y)$ and binning of $y$.

In principle, you should convince other core contributors to add a reference. Here, I want to remove one where we (currently) disagree.
@ogrisel I would therefore strongly encourage you not to block this PR. Please.

@betatim

betatim commented Jun 17, 2026

Copy link
Copy Markdown
Member

I am surprised by the amount of discussion this is generating. As someone who knew nothing about this topic my first thought was "use variable width bins, make sure each one has roughly the same amount of samples in it, use as many bins as you reasonably can without blowing up the uncertainty due to low stats in each bin". So I started skimming through some of the various papers, asking perplexity to summarise some of them, and asked perplexity to do some basic research into where the idea of the cube root comes from (I find that result surprising, why should it be the cube root of the number of samples?). It seems that the reason it is called "rice rule" is because someone at RICE university mentioned that things scale with the cube root in passing in their lecture notes from the middle of the 80s. You arrive at this rule if you want the variance and bias of the quantity you are estimating in the bin to balance/be equal (expressed as a true newbie and hand wavy physicist). The fact that someone put this in lecture notes and didn't bother to write a paper makes me think they thought that this is not a particularly interesting result/not a lot of work went into figuring it out.

Dimitriadis 2021 mentions this rule but only to argue for their CORP method is better. They don't give a reference and instead use a few sentences to arrive at the result. This makes me think that this is somehow "standard knowledge" and not a result that had to be discovered.

I don't understand enough about the business of calibration to know why it isn't "just" an application of histograms to estimate a quantity. If there is nothing special here then I am surprised someone wrote a paper specifically showing that the cube root rule which is "standard knowledge" for choosing the number of bins if you think that balancing the variance and bias is the thing you want to do.

So, as a naive onlooker I think we have bigger fish to fry than discuss who truly was the first to derive and publish a result that 40 years ago was mentioned in some lecture notes. It feels a bit like discussing who to cite when using the formula for the mean squared error (I am sure someone first though of it, but today I would tell people to get lost if they wanted me to cite a particular paper. Or start adding references for using addition, multiplication, etc...)

@betatim

betatim commented Jun 17, 2026

Copy link
Copy Markdown
Member

The bigger fish could be: work on adding a method that does not need binning or make sure that users understand that they need to look at the calibration display's plot with their own eyes and brain turned on, maybe try out a few different values for n_bins and then make a judgement.

@lorentzenchr

Copy link
Copy Markdown
Member Author

@betatim Thanks for your thorough input. Do you have a proposal for this PR? Remove all references (my original proposal)?

@ogrisel

ogrisel commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

work on adding a method that does not need binning or make sure that users understand that they need to look at the calibration display's plot with their own eyes and brain turned on, maybe try out a few different values for n_bins and then make a judgement.

Yes we can do that but the binned calibration curve is the most used tool for calibration evaluation and is actually asymptotically consistent with the cube-root rule. So this is a baseline that deserves being implemented in scikit-learn, irrespective of which reference we cite.

The discussion here is about respecting the anteriority of the asymptotic result of the cube root rule. @lorentzenchr states that this is a direct consequence of the cube-root rules of histograms proved asymptotically optimal in Scott 1979 but to me this is not so obvious because a regressograms (like the binned calibration curve is a particular example) and a histogram are two different mathematical objects. I could not find classical references that explicitly prove (or even mention) that property for regressograms. Let me review the original proof again of Scott with Claude to convince myself whether the regressogram results is a direct transposition or not.

@betatim

betatim commented Jun 17, 2026

Copy link
Copy Markdown
Member

I'm not suggesting that we don't include this feature. Like you said, it is useful and I think for many practical use-cases it is a good/very good solution.

My recommendation is to include all three references that are currently on the table. Having a handful (less than five) of references seems like a reasonable number to have. It doesn't overwhelm the reader who really wants to know about the nitty gritty. Neither of the references appear off topic to me.

Adding an additional reference is free, as long as the total number of references isn't too big and the references are all on topic. We don't have to be the arbiter of what is truly the first/only/authoritative reference. For this particular case it does not feel like we are participating in "SEO for references"/citation farming.

My goal is to find a compromise that allows us to move on to other topics.

@ogrisel

ogrisel commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

I dug further, and adapting the original proof scheme of Scott 1979 to the analysis of the regressogram estimator (for the original equal-width case) is possible but not so trivial:

https://claude.ai/share/dbf08976-cf3b-45fb-a2cd-1303000b2552

image

In particular any naive transposition to set the constant based on the spread IQR of the distribution of the predictions (i.e. the "fd" rule of numpy) would be unfounded.

So while I am fine stating that the cube-root rule can be adapted from the asymptotic analysis of the histogram estimator of Scott 1979 (equal width binning) or Terrell and Scott 1985 (for the analysis of equal-mass histograms), I also think that we should legitimately cite more recent references that specifically study binned calibration curves as we currently have in main.

@ogrisel

ogrisel commented Jun 17, 2026

Copy link
Copy Markdown
Member

My goal is to find a compromise that allows us to move on to other topics.

I also find it interesting to leverage that discussion to help us reach a shared understanding on the good practice of the impacts of the choice of those parameters in order to improve the educational value of our docstrings and guide the choice of default values.

@lorentzenchr

lorentzenchr commented Jun 20, 2026 •

Copy link
Copy Markdown
Member Author

For the statisticians interested in history: The earliest reference of "regressogram" seems to be Tukey 1961.

@lorentzenchr

lorentzenchr commented Jun 20, 2026 •

Copy link
Copy Markdown
Member Author

For the readers of Annals of Statistics, the asymptotic optimal number of bins was proven by Spiegelman & Sacks (1980) (and others), and summarized (therefore for me a bit easier to read) and generalized by Stone (1982) (a "special invited paper"!).

@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Jun 22, 2026
@lorentzenchr

Copy link
Copy Markdown
Member Author

@ogrisel Is this PR now good for you?

@lorentzenchr

Copy link
Copy Markdown
Member Author

@ogrisel @betatim could you please merge, this is a clear and small doc improvement.

@lorentzenchr lorentzenchr added this to the 1.10 milestone Jul 13, 2026

@betatim betatim 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 fine with the change to the text.

In this case I have no opinion on who we cite or not cite. It seems like one can make a reasonable pro/con each individual reference.

@lorentzenchr

Copy link
Copy Markdown
Member Author

@betatim @antoinebaker as just discussed, are you fine? can you merge?

@antoinebaker antoinebaker 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 cannot merge but I'm fine with the changes.

@lorentzenchr

Copy link
Copy Markdown
Member Author

@antoinebaker Thanks for your approval. Means something to me!

@betatim
betatim enabled auto-merge (squash) July 27, 2026 15:53
@betatim
betatim merged commit 6abc22c into scikit-learn:main Jul 27, 2026
33 checks passed
@lorentzenchr

Copy link
Copy Markdown
Member Author

@betatim THX

@lorentzenchr
lorentzenchr deleted the doc_calibration_references branch July 27, 2026 15:59
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks done
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.

4 participants