Skip to content

Calibration and Refinement loss for Brier score loss #21774

Open

Description

@ColdTeapot273K

Describe the workflow you want to enable

As per Brier score User Guide:

“Only when refinement loss remains the same does a lower Brier score loss always mean better calibration”

But the current API doesn't provide refinement loss/calibration loss.
Which makes it hard to measure the quality of probabilistic estimates.

Describe your proposed solution

My proposed solution involves implementing the one described in the paper [Flach2008]
, the reference which is conveniently already mentioned in the User Guide

Namely, estimating Calibration loss and Refinement loss without any binning, on raw data/predictions.

If the community decides this is a valuable addition, I humbly present my implementation, which is WIP in terms of Scikit-Learn codebase conventions compliance and corner case processing, but is functioning in essence.

Describe alternatives you've considered, if relevant

Visual comparison of calibration curves
<not exact, not scalable

Making custom ad hoc metrics to estimate probability errors
<fragile, dubious

Using sklearn.calibration.calibration_curve
<requires binning1

Using #11096
<requires binning1

1 Now, problem with binning is described in [Bella2012]. To quote:

The problem of using bins is that if too few bins are defined, the real probabilities are
not properly detailed to give an accurate evaluation. If too many bins are defined, the real
probabilities are not properly estimated. A partial solution to this problem is to make the bins
overlap.

And using overlapping bins seems like and additional degree of freedom, additional parameter one'd have to keep in mind, tune and argue about with collegues.

Additional context

I'm aware that contributors to #11096 have done work in implementing Calibration loss with binning and clarifying docs on calibration topic in general. So I'd like to get feedback on that and I'm open to suggestions how to proceed.

UPD:
Closes #18268, #21718

Activity

  1. added
    Needs Triage
    on Jan 21, 2022
  2. added and removed
    Needs Triage
    on Feb 10, 2022
  3. added
    Needs Decision - Include Feature
    on Apr 24, 2022
  4. ogrisel commented on May 17, 2022

    @ogrisel
    Member

    There is a related proposal by @lorentzenchr to implement binless calibration curves using CORP method and the PAV / istonic regression aglorithm in #23132. The paper linked in this issue also proposes an estimate of a decomposition of the Brier score into 3 terms: miscalibration, refinement / discrimination and irreducible Brier loss.

    I still need to read all those papers in details to get a clear understanding on how they relate to decide what should be done in scikit-learn.

  5. ogrisel commented on May 17, 2022

    @ogrisel
    Member

    @ColdTeapot273K @lorentzenchr if you already have a good understanding of both approaches, I would love you to share your analysis of the pros and cons of each.

  6. lorentzenchr commented on Jun 21, 2022

    @lorentzenchr
    Member

    In the end, every method uses bins, but they differ in its construction.
    The CORP approach, however, has clearly stated beneficial properties and is generic in that it can be used on probabilistic classification and regression problems which enables a general solution to score decompositions.

  7. ColdTeapot273K commented on Jun 21, 2022

    @ColdTeapot273K
    Author

    @lorentzenchr I'm not sure I can fully agree on "every method here uses bins".

    This implementation kinda pools similar predictions into the same "bucket" indeed, but that "bucket" is the exact number and not an interval (conceptually at least; i omit the problems of floating point arithmetics and epsilon). Binning implies discretization and here no discretization is performed, it operates on continuous values (the key point).

    Also could you clarify what do you refer to as "CORP approach" (didn't see references mentioning that in the triaging PR thread) and what do you refer to as "clearly states beneficial properties" and how are they ultimately more beneficial than the benefits of the exaxct/binless implementation, which I mention here? if that's your point


    If you insist that there certainly are practical benefits to binned implementation ...

    (vs exact impl or vs binning pred_proba outputs and supplying them to the exact impl and thus having binned by user whatever way they like)

    ... then, as an engineer it makes sense to me to use a strategy pattern (inside one function) to allow a user to switch between exact/binned logics, the same way we switch between l1 and l2 or between different optimizers/solvers for an estimator. How about that?

  8. lorentzenchr commented on Jun 27, 2022

    @lorentzenchr
    Member

    could you clarify what do you refer to as "CORP approach"

    See #21774 (comment), arxiv link is https://arxiv.org/abs/2008.03033.

    This issue will be solved if we solve the broader (but not much more difficult) #23767.

  9. lorentzenchr commented on Feb 26, 2023

    @lorentzenchr
    Member

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

    from model_diagnostics.scoring import SquaredError, decompose
    
    se = SquaredError()
    y_true = [0, 0, 0, 1, 1, 1]
    y_pred = [0.1, 0.4, 0.3, 0.3, 0.99, 0.9]  # model.predict_proba(X)
    decompose(se, y_true, y_pred)
    ┌────────────────┬────────────────┬─────────────┬──────────┐
    │ miscalibration ┆ discrimination ┆ uncertainty ┆ score    │
    │ ---            ┆ ---            ┆ ---         ┆ ---      │
    │ f64            ┆ f64            ┆ f64         ┆ f64      │
    ╞════════════════╪════════════════╪═════════════╪══════════╡
    │ 0.015572       ┆ 0.138889       ┆ 0.25        ┆ 0.126683 │
    └────────────────┴────────────────┴─────────────┴──────────┘
    

    Note that the Brier score is the squared error, just a different name.

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