Skip to content

Additive Score/Metric decomposition into Miscalibration, Discrimination and Uncertainty #23767

Open

Description

@lorentzenchr

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

  1. added
    Needs Triage
    Needs Decision - Include Feature
    and removed
    Needs Triage
    on Jun 27, 2022
  2. wenhaoz-fengcai commented on Jun 29, 2022

    @wenhaoz-fengcai

    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

  3. e-pet commented on Jun 30, 2022

    @e-pet

    Something like this?

    import numpy as np
    from sklearn.isotonic import IsotonicRegression
    
    def score_decompose(target, pred_probs, scoring_function):
        # See Dimitriadis, Gneiting, Jordan (2021), https://www.pnas.org/doi/full/10.1073/pnas.2016191118
        target = target.squeeze()
        score = lambda probs: scoring_function(target, probs)
        pred_probs = pred_probs.squeeze()
        isotonic = IsotonicRegression(out_of_bounds='clip', y_min=0, y_max=1)
        isotonic.fit(pred_probs, target)
        isotonic_probs = isotonic.predict(pred_probs)
        base_probs = np.ones_like(target) * np.mean(target)
        # miscalibration
        mcb = score(pred_probs) - score(isotonic_probs)
        # discrimination
        dsc = score(base_probs) - score(isotonic_probs)
        # uncertainty
        unc = score(base_probs)
        # the score should decompose as SCORE = MCB - DSC + UNC
        total_score = score(pred_probs)
        assert(np.abs((total_score - mcb + dsc - unc) / total_score) < 1e-5)
    
        return total_score, mcb, dsc, unc
  4. e-pet commented on Jun 30, 2022

    @e-pet

    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?

  5. lorentzenchr commented on Jul 2, 2022

    @lorentzenchr
    MemberAuthor

    @e-pet Thanks for the code snippet. I think this is it. But we need some clever design of the API:

    1. How should score_decompose know if one aims for predicting the expectation (like for the Brier score) or a quantile (with pinball loss)?
    2. How to pass additional parameters of a metric like the quantile level alpha of mean_pinball_loss?
  6. wschella commented on Jul 6, 2022

    @wschella

    Regarding point 2, you could do it on the caller side like this, without adding an explicit API for it.

    bs = lambda t, p: brier_score_loss(t, p, extra_args)
    score_decompose(target, pred_probs, bs)
  7. lorentzenchr commented on Jul 7, 2022

    @lorentzenchr
    MemberAuthor

    That does not work. The score decomposition needs to compute alpha-quantiles. Therefore it needs to know:

    • which statistic to compute: here a quantile
    • parameters of the statistic: here alpha
  8. e-pet commented on Jul 8, 2022

    @e-pet

    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, but

    • the pinball loss is a proper scoring rule, for any alpha, that measures the deviation of the predictions from the $\alpha$-quantile, and
    • score_decompose provides 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.)

  9. wenhaoz-fengcai commented on Jul 8, 2022

    @wenhaoz-fengcai

    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?

    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?

    BSterms

    [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

  10. lorentzenchr commented on Jul 8, 2022

    @lorentzenchr
    MemberAuthor

    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.

  11. wenhaoz-fengcai commented on Jul 8, 2022

    @wenhaoz-fengcai

    @lorentzenchr Thanks for the clarification.

  12. lorentzenchr commented on Feb 26, 2023

    @lorentzenchr
    MemberAuthor

    For those interested, this is now available in the new package model-diagnostics with

    from model_diagnostics.scoring import decompose
  13. ogrisel commented on May 22, 2023

    @ogrisel
    Member

    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]):

    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.

  14. ogrisel commented on Dec 10, 2023

    @ogrisel
    Member

    My main concern with the CORP reliability diagrams is that they are very square-looking on finite size test sets, see for instance:

    image

    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

    image

  15. ogrisel commented on Dec 10, 2023

    @ogrisel
    Member

    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.

  16. e-pet commented on Dec 10, 2023

    @e-pet

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

  17. ogrisel commented on Dec 10, 2023

    @ogrisel
    Member

    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.

  18. lorentzenchr commented on Dec 10, 2023

    @lorentzenchr
    MemberAuthor

    I transfered the comment/discussion to #23132.

  19. GaelVaroquaux commented on Apr 16, 2026

    @GaelVaroquaux
    Member

    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)

  20. lorentzenchr commented on Apr 16, 2026

    @lorentzenchr
    MemberAuthor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Decision - Include FeatureNew Featuremodule:metrics

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions