From 57940d9d4204a7bab916bd74ff81264957265d3b Mon Sep 17 00:00:00 2001 From: rbalachandar Date: Sun, 3 May 2026 20:23:37 +0200 Subject: [PATCH] Fix invalid escape sequences in calibration.py docstrings - Changed docstrings to raw strings (r"""...""") to preserve backslashes - Fixes SyntaxWarning about invalid escape sequences in LaTeX math notation - Lines affected: ece_confidence_multiclass() and ece_confidence_binary() This resolves the syntax warnings that appeared when running tests, such as: "SyntaxWarning: invalid escape sequence '\c'" which occurred in LaTeX expressions like \frac and \cdot within the docstrings. --- pyhealth/metrics/calibration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyhealth/metrics/calibration.py b/pyhealth/metrics/calibration.py index 32e27b617..d8cea6a8d 100644 --- a/pyhealth/metrics/calibration.py +++ b/pyhealth/metrics/calibration.py @@ -99,7 +99,7 @@ def _ECE_classwise(prob:np.ndarray, label_onehot:np.ndarray, bins=20, threshold= return summs, class_losses def ece_confidence_multiclass(prob:np.ndarray, label:np.ndarray, bins=20, adaptive=False): - """Expected Calibration Error (ECE). + r"""Expected Calibration Error (ECE). We group samples into 'bins' basing on the top-class prediction. Then, we compute the absolute difference between the average top-class prediction and @@ -133,7 +133,7 @@ def ece_confidence_multiclass(prob:np.ndarray, label:np.ndarray, bins=20, adapti return _ECE_confidence(df, bins, adaptive)[1] def ece_confidence_binary(prob:np.ndarray, label:np.ndarray, bins=20, adaptive=False): - """Expected Calibration Error (ECE) for binary classification. + r"""Expected Calibration Error (ECE) for binary classification. Similar to :func:`ece_confidence_multiclass`, but on class 1 instead of the top-prediction.