Repository navigation
Description
Describe the workflow you want to enable
Proposition
I'd like to decompose scores (at least the ones from consistent scoring functions for identifiable functionals) into meaningful additive components:
- MSC ≥ 0 miscalibration (for Brier score also know as reliability term)
- DSC ≥ 0 discrimination (for Brier score also know as resolution term)
- UNC ≥ 0 uncertainty or entropy
as (lower is better) score_loss = MSC - DSC + UNC, see [1, 2, 3, 4]. An implementation in R is available at [5].
For classification with Brier score
from sklearn.metrics import brier_score_loss, score_decompose
model.fit(X_train, y_train)
y_pred = model.predict(y_test)
msc, dsc, unc = score_decompose(y_test, y_pred, brier_score_loss)
assert msc - dsc + unc = brier_score_loss(y_test, y_pred)For quantile regression with pinball loss
rom sklearn.metrics import mean_pinball_loss, score_decompose
alpha = 0.8 # the 80% quantile
model.set_params(quantile=alpha).fit(X_train, y_train)
y_pred = model.predict(y_test)
msc, dsc, unc = score_decompose(y_test, y_pred, brier_score_loss, alpha=alpha)
assert msc - dsc + unc = mean_pinball_loss(y_test, y_pred, alpha=alpha)References
[1] Pohle (2020) https://arxiv.org/abs/2005.01835
[2] Dimitriadis, Gneiting, Jordan (2020) https://arxiv.org/abs/2008.03033
[3] Gneiting & Resin (2021) https://arxiv.org/abs/2108.03210
[4] Fissler, Lorentzen & Mayer (2022) https://arxiv.org/abs/2202.12780
[5] https://github.com/aijordan/reliabilitydiag
Describe your proposed solution
From [2]:
While there is a consensus on the character and intuitive interpretation of the decomposition terms, their exact form remains subject to debate, despite a half century quest in the wake of Murphy’s [1973] Brier score decomposition. In particular, Murphy’s decomposition is exact in the discrete case, but fails to be exact under continuous forecasts, which has prompted the development of increasingly complex types of decompositions (...).
In the extant literature, it has been assumed implicitly or explicitly that the calibrated and reference forecasts can be chosen at researchers’ discretion (...). We argue otherwise and contend that the calibrated forecasts ought to be the PAV-(re)calibrated probabilities, as displayed in the CORP reliability diagram, whereas the reference forecast r ought to be the marginal event frequency (...). We refer to the resulting decomposition as the CORP score decomposition, which enjoys the following properties:
• MCB ≥ 0 with equality if the original forecast is calibrated.
• DSC ≥ 0 with equality if the PAV-calibrated forecast is constant.
• The decomposition is exact.
Perhaps surprisingly, the PAV algorithm and its appealing properties generalize from prob-
abilistic classifiers to mean, quantile, and expectile assessments for real-valued outcomes
Describe alternatives you've considered, if relevant
No response
Additional context
#23132 is related and might be a good first step towards score_decomposition.
Solving this issue will also solve #21774.
Activity
wenhaoz-fengcai commentedon Jun 29, 2022
Hi everyone, I was looking for this function recently and only found that Tensorflow has it implemented. So I have implemented a small code snippet for this functionality according to [1,2]. My starting code snippet is here.
Hope this will be helpful for anyone interested in.
[1] Siegert, Stefan. "Simplifying and generalising Murphy's Brier score decomposition." Quarterly Journal of the Royal Meteorological Society 143.703 (2017): 1178-1183.
[2] https://cawcr.gov.au/projects/verification/reliability_resolution.html
e-pet commentedon Jun 30, 2022
Something like this?
e-pet commentedon Jun 30, 2022
Edit: had not seen the comment by @wenhaoz-fengcai, sorry. I believe you are not using the isotonic regression / PAV solution described in the Dimitriadis paper, though?
lorentzenchr commentedon Jul 2, 2022
@e-pet Thanks for the code snippet. I think this is it. But we need some clever design of the API:
score_decomposeknow if one aims for predicting the expectation (like for the Brier score) or a quantile (with pinball loss)?alphaofmean_pinball_loss?wschella commentedon Jul 6, 2022
Regarding point 2, you could do it on the caller side like this, without adding an explicit API for it.
lorentzenchr commentedon Jul 7, 2022
That does not work. The score decomposition needs to compute alpha-quantiles. Therefore it needs to know:
e-pet commentedon Jul 8, 2022
Sorry, I don't yet understand the problem. Why doesn't
score_decompose(target, pred_probs, lambda t, p: mean_pinball_loss(t, p, alpha=...))do what you want? I honestly do not yet understand why one would want to do that / how you would interpret the result, butscore_decomposeprovides decompositions for any proper scoring rule.Again, I am not really sure how you would interpret the result, though.
If uncertainty quantification / quantile estimation for the different components of the decomposition is what you are after - that is a very different thing, I believe? For that, you would basically need to estimate the posterior distribution of possible calibration curves, and then compute the decompositions based on each of those. I am currently playing around with something like this (they also have a bootstrapping approach in their paper, BTW) but am not yet fully convinced that it's useful. It's definitely not trivial, and the version they have in their paper doesn't seem ideal to me, to be honest. (Maybe for that reason, they also do not show uncertainty estimates for the decomposition components, even though they do estimate a distribution of calibration curves. But maybe I'm also just not getting something.)
wenhaoz-fengcai commentedon Jul 8, 2022
Hi @e-pet , the code snippet is an implementation of [1][2]. I'm not sure why isotonic score should be used. It is not mentioned in this formula, right?
[1] Siegert, Stefan. "Simplifying and generalising Murphy's Brier score decomposition." Quarterly Journal of the Royal Meteorological Society 143.703 (2017): 1178-1183.
[2] https://cawcr.gov.au/projects/verification/reliability_resolution.html
lorentzenchr commentedon Jul 8, 2022
Please refer to any of the first four references in the top of this issue, in particular [2] for why isotonic regression (PAV algo) is desirable (there called CORP approach).
Then, such a decomposition is much more general than only for the Brier score. Even for the Brier, you need to know that you predict the expected value of the class Y conditional on X, i.e. E[Y|X]. From this stems the term "\bar{o}_k", i.e. the expectation of Y given the prediction p, i.e. E[Y|prediction(X)=p]. For a consistent scoring function for quantile (regression) like the pinball loss, this term would be the quantile at level alpha conditional on a given model prediction, which needs to be estimated with the given data.
wenhaoz-fengcai commentedon Jul 8, 2022
@lorentzenchr Thanks for the clarification.
lorentzenchr commentedon Feb 26, 2023
For those interested, this is now available in the new package model-diagnostics with
ogrisel commentedon May 22, 2023
There is also this recent paper that studies both theoretically and empirically different ways to quantify calibration error (in the case where f(X) is an estimate of E[Y|X]):
Jarosław Błasiok, Parikshit Gopalan, Lunjia Hu, Preetum Nakkiran,
https://arxiv.org/abs/2211.16886
Unfortunately they do not study the MSC term of the CORP decomposition. I would be interesting to see if MSC has some of the favorable properties Błasiok et al. look for.
ogrisel commentedon Dec 10, 2023
My main concern with the CORP reliability diagrams is that they are very square-looking on finite size test sets, see for instance:
Those diagrams would probably qualitatively look very different in the asymptotic regime of large test sets.
To avoid this finite test sample artifact, we might also what to consider methods such as implemented in:
https://github.com/apple/ml-calibration
Smooth ECE: Principled Reliability Diagrams via Kernel Smoothing
Jarosław Błasiok, Preetum Nakkiran
https://arxiv.org/abs/2309.12236
ogrisel commentedon Dec 10, 2023
Or a method based on bagging on the test set with randomized bin edges. But that would be prior art (I am not sure, I did not try to do a full literature review) and we would rather avoid prior art in scikit-learn as per our inclusion criteria.
e-pet commentedon Dec 10, 2023
@ogrisel Your concern seems to be more with the CORP-based reliability diagrams and less with the decomposition proposed here, I think?
If you want smooth reliability diagrams, my current go-to solution is the loess-based version + bootstrapped confidence, see e.g. https://onlinelibrary.wiley.com/doi/epdf/10.1002/sim.6167. This would actually be super useful to have available as a standard option in sklearn I think. (I have a version of that implemented here in a project-specific repo, using statsmodels loess because sklearn doesn't have it, although there is currently an active pull request on the topic.)
But again, that's quite separate from the issue discussed here, I believe?
ogrisel commentedon Dec 10, 2023
I agree, the CORP decomposition is informative (and simple to compute for any proper scoring rule, both for classification and regression), but my point would be to not necessarily tie it too much to the CORP way of estimating the MSC term.
lorentzenchr commentedon Dec 10, 2023
I transfered the comment/discussion to #23132.
GaelVaroquaux commentedon Apr 16, 2026
Related #18268
IMHO, we should start by implementing ECE which is a standard in machine learning (and I believe that there is a PR for it somewhere)
lorentzenchr commentedon Apr 16, 2026
In the light of https://arxiv.org/abs/2510.23821, I think the miscalibration from a score decomposition (L2 calibration error instead of L1) is a better measure of miscalibration than ECE.