-
Notifications
You must be signed in to change notification settings - Fork 413
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
for BinaryCalibrationError the n_bins needs to be 1 less than actual to match manual calculation #1907
Comments
Hi! thanks for your contribution!, great first issue! |
Hi @mshergad, thanks for raising this issue. torch.linspace(0,1,n_bin) I get torch.linspace(0,1,n_bin+1) I get |
Thanks for the example. I can definitely see now this is some corner case that we are not covering right now. from torchmetrics.functional.classification import binary_calibration_error
from netcal.metrics import ECE
import torch
from torch import tensor
preds = tensor([0.9000, 0.9000, 0.9000, 0.9000, 0.9000, 0.8000, 0.8000, 0.0100, 0.3300, 0.3400, 0.9900, 0.6100], dtype=torch.float64)
target = tensor([1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0])
print(binary_calibration_error(preds, target, n_bins=99, norm="l1")) # tensor(0.4733, dtype=torch.float64)
print(binary_calibration_error(preds, target, n_bins=100, norm="l1")) # tensor(0.4183, dtype=torch.float64)
print(ECE(99).measure(preds.numpy(), target.numpy())) # 0.4733333333333334
print(ECE(100).measure(preds.numpy(), target.numpy())) # 0.4733333333333333 they also have a |
Just saw that calibration curve in sklearn also has a |
Okay, after further investigation it seems to just be a matter of precision e.g.
instead dtype=torch.float it should be dtype=confidences.dtype .Fix is implemented in PR #1919, with the example provided in this issue added as an unit test. |
That’s great to hear that you’ve found the issue! I wasn’t able to grock how a precision error caused this change but I really appreciate your quick responses and actions. Thanks! |
🐛 Bug
given this example
the number of bins are 2 but they should be 3 since there are three probability values -- not sure if this is a documentation error or a bug
To Reproduce
Steps to reproduce the behavior...
Code sample
Expected behavior
Environment
conda
,pip
, build from source):Additional context
The text was updated successfully, but these errors were encountered: