Improve exception handling
This commit is contained in:
parent
0ceec7a819
commit
e2798436b3
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +21,18 @@ def calibration_curve(y_true, y_prob, *, n_bins=5, strategy="uniform"):
|
||||||
"must be either 'quantile' or 'uniform'."
|
"must be either 'quantile' or 'uniform'."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
binids = np.digitize(y_prob, bins) - 1
|
binids = np.digitize(y_prob, bins) - 1
|
||||||
|
except Exception as e:
|
||||||
|
np.set_printoptions(threshold=sys.maxsize)
|
||||||
|
logging.info("=" * 40)
|
||||||
|
logging.info(f"n_bins={n_bins}, strategy={strategy}")
|
||||||
|
logging.info(f"y_true={repr(y_prob)}")
|
||||||
|
logging.info(f"bins={repr(bins)}")
|
||||||
|
logging.info("=" * 40)
|
||||||
|
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
bin_sums = np.bincount(binids, weights=y_prob, minlength=len(bins))
|
bin_sums = np.bincount(binids, weights=y_prob, minlength=len(bins))
|
||||||
bin_true = np.bincount(binids, weights=y_true, minlength=len(bins))
|
bin_true = np.bincount(binids, weights=y_true, minlength=len(bins))
|
||||||
|
|
18
strmlt.py
18
strmlt.py
|
@ -165,24 +165,14 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
for strategy in ['uniform', 'quantile']:
|
|
||||||
for n_bins in range(1, 300):
|
|
||||||
try:
|
try:
|
||||||
fig = plotly_calibration(y_true, y_pred, n_bins=n_bins, strategy=strategy)
|
fig = plotly_calibration(y_true, y_pred, n_bins=n_bins, strategy=strategy)
|
||||||
# st.plotly_chart(fig, use_container_width=True)
|
st.plotly_chart(fig, use_container_width=True)
|
||||||
|
|
||||||
fig = plotly_calibration_odds(y_true, y_pred, n_bins=n_bins, strategy=strategy)
|
fig = plotly_calibration_odds(y_true, y_pred, n_bins=n_bins, strategy=strategy)
|
||||||
# st.plotly_chart(fig, use_container_width=True)
|
st.plotly_chart(fig, use_container_width=True)
|
||||||
|
except Exception as e:
|
||||||
except:
|
st.warning("Hey! Unfortunately, a very mysterious error occured. Try refreshing the page or changing the number of bins a bit.")
|
||||||
st.warning("Hey! Unfortunately, there occured a mysterious error, which I haven't been able to reproduce locally. Try refreshing the page or changing the number of bins a bit. <3")
|
|
||||||
|
|
||||||
np.set_printoptions(threshold=sys.maxsize)
|
|
||||||
logging.info("=" * 40)
|
|
||||||
logging.info(f"n_bins={n_bins}, strategy={strategy}")
|
|
||||||
logging.info(f"true={repr(y_true)}")
|
|
||||||
logging.info(f"y_pred={repr(y_pred)}")
|
|
||||||
logging.info("=" * 40)
|
|
||||||
|
|
||||||
# overconf = overconfidence(y_true, y_pred)
|
# overconf = overconfidence(y_true, y_pred)
|
||||||
# st.write(f"Your over/under- confidence score is {overconf:.2f}.")
|
# st.write(f"Your over/under- confidence score is {overconf:.2f}.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user