EFS-OpenSource / calibration-framework

The net:cal calibration framework is a Python 3 library for measuring and mitigating miscalibration of uncertainty estimates, e.g., by a neural network.
https://efs-opensource.github.io/calibration-framework/
Apache License 2.0
336 stars 42 forks source link

Re-using HistogramBinning #22

Closed jwitos closed 1 year ago

jwitos commented 3 years ago

Hi, I noticed the following behavior when using HistogramBinning:

from netcal.binning import HistogramBinning
import numpy as np

labels = np.random.randint(2, size=(100,))
preds = np.random.uniform(size=(100,))

estimator = HistogramBinning()
for i in range(2):
    print(f"Loop {i}")
    estimator.fit(preds, labels)

with the code above, first loop will run correctly but second will throw AttributeError: Parameter 'bins' must be int for classification mode. (as this line changes bins from int to array).

This can be fixed by re-initializing HistogramBinning every time in the loop, but this error doesn't show up in other estimators so I thought it would be worth bringing up here. Maybe there's a way to avoid this, and if not I'll keep this issue for others that might encounter this problem.