From 93bbeee7899d1096f1053d74fb3f4cf7cc125fa1 Mon Sep 17 00:00:00 2001 From: yagudin Date: Tue, 1 Jun 2021 17:22:47 +0300 Subject: [PATCH] Add clipping in plotting.transform --- plotting.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plotting.py b/plotting.py index bb6a6f6..17dbf13 100644 --- a/plotting.py +++ b/plotting.py @@ -73,6 +73,14 @@ def plotly_calibration(y_true, y_pred, n_bins, strategy="quantile"): return fig +def transform(x): + """ + e.g. 66.6% → 2^{1} : 1 → 1 + """ + x = np.clip(x, 1e-3, 1-1e-3) # used when computing error bars close to 0 or 1. + return np.log2(1 / (1 - x) - 1) + + def plotly_calibration_odds(y_true, y_pred, n_bins, strategy="quantile"): y_pred = np.clip(y_pred, 0.005, 0.995) # clipping to avoid undefined odds y_true = np.clip(y_true, 1e-3, 1 - 1e-3) @@ -83,8 +91,6 @@ def plotly_calibration_odds(y_true, y_pred, n_bins, strategy="quantile"): fig = go.Figure() - transform = lambda x: np.log2(1 / (1 - x) - 1) # 66.6% → 2^{1}:1 → 1 - customdata = np.dstack( [ counts,