Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pearsonify/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np


def compute_pearson_residuals(y_true, y_pred_proba):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Align the statistical meaning of q_alpha with its new usage or rename it for clarity.

The old CI used np.sqrt(q_alpha * p * (1 - p)), consistent with q_alpha as a chi-square–style factor under the square root. The new form p ± q_alpha * sqrt(p(1-p)) treats q_alpha as a z-score. If callers still pass values tuned for the old meaning, intervals will be incorrectly scaled. Please either update call sites/docs to reflect the z-score interpretation or rename the parameter (e.g., z_alpha) to make the change explicit.

"""Compute Pearson residuals for binary classification."""
y_pred_proba = np.clip(y_pred_proba, 1e-10, 1 - 1e-10)
Expand All @@ -8,8 +9,9 @@ def compute_pearson_residuals(y_true, y_pred_proba):

def compute_confidence_intervals(y_pred_proba, q_alpha):
"""Compute confidence intervals based on Pearson residuals."""
lower_bounds = np.maximum(0, y_pred_proba - np.sqrt(q_alpha * y_pred_proba * (1 - y_pred_proba)))
upper_bounds = np.minimum(1, y_pred_proba + np.sqrt(q_alpha * y_pred_proba * (1 - y_pred_proba)))
std_error = np.sqrt(y_pred_proba * (1 - y_pred_proba))
lower_bounds = np.maximum(0, y_pred_proba - q_alpha * std_error)
upper_bounds = np.minimum(1, y_pred_proba + q_alpha * std_error)
return lower_bounds, upper_bounds


Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pythonpath = ["."]
[tool.ruff]
line-length = 88
target-version = "py39"
select = ["E", "F", "W", "I", "N", "B", "C4", "UP"]
ignore = ["E203", "E501"]
lint.select = ["E", "F", "W", "I", "N", "B", "C4", "UP"]
lint.ignore = ["E203", "E501"]

[tool.ruff.format]
docstring-code-format = true
Expand Down