Skip to content

Conversation

@RektPunk
Copy link

@RektPunk RektPunk commented Jan 9, 2026

Description

This PR addresses a mathematical inconsistency in the compute_confidence_intervals function.
Previously, the code applied a square root to the quantile value (q_alpha) when calculating the interval bounds.

However, based on the definition of Pearson residuals: $r_i = \frac{y_i - \hat{p}_i}{\sqrt{\hat{p}_i(1 - \hat{p}_i)}}$
To satisfy the condition , the bounds should be calculated as: $\hat{p}_i \pm q_a \sqrt{\hat{p}_i(1 - \hat{p}_i)}$

Key Changes

  • Updated compute_confidence_intervals to use q_alpha * np.sqrt(...) instead of np.sqrt(q_alpha * ...).

Summary by Sourcery

Correct the computation of confidence intervals based on Pearson residuals and update linter configuration to the current Ruff schema.

Bug Fixes:

  • Fix confidence interval bounds to use the quantile multiplier times the standard error instead of taking the square root of the product.

Enhancements:

  • Refactor confidence interval computation to reuse a named standard error term for clarity.

Build:

  • Update Ruff configuration keys in pyproject.toml to use the new lint.select and lint.ignore options.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the confidence interval computation for Pearson residuals to use the quantile as a linear multiplier of the standard error, and updates Ruff configuration keys to the current schema.

File-Level Changes

Change Details Files
Correct confidence interval formula to match Pearson residual definition and improve numerical clarity.
  • Refactored confidence interval computation to factor out the standard error term sqrt(p*(1-p)).
  • Changed lower and upper bounds to subtract/add q_alpha multiplied by the standard error instead of taking the square root of q_alpha * p * (1-p).
  • Maintained clipping of bounds to [0, 1] using np.maximum and np.minimum.
pearsonify/utils.py
Update Ruff configuration keys to the newer lint.* schema.
  • Replaced top-level select option with lint.select in Ruff configuration.
  • Replaced top-level ignore option with lint.ignore in Ruff configuration.
  • Kept existing rule sets and ignored codes unchanged while aligning with updated Ruff config structure.
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider clarifying in the function (e.g., via parameter name or a short comment) whether q_alpha is expected to be a z-score, t-quantile, or something else, so its intended scaling in the interval formula is unambiguous to callers.
  • The switch to lint.select / lint.ignore under [tool.ruff] assumes a newer Ruff config style; double-check that this matches the Ruff version used in this project, otherwise these options may be ignored.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider clarifying in the function (e.g., via parameter name or a short comment) whether `q_alpha` is expected to be a z-score, t-quantile, or something else, so its intended scaling in the interval formula is unambiguous to callers.
- The switch to `lint.select` / `lint.ignore` under `[tool.ruff]` assumes a newer Ruff config style; double-check that this matches the Ruff version used in this project, otherwise these options may be ignored.

## Individual Comments

### Comment 1
<location> `pearsonify/utils.py:4` </location>
<code_context>
 import numpy as np

+
 def compute_pearson_residuals(y_true, y_pred_proba):
     """Compute Pearson residuals for binary classification."""
     y_pred_proba = np.clip(y_pred_proba, 1e-10, 1 - 1e-10)
</code_context>

<issue_to_address>
**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.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

@RektPunk
Copy link
Author

Hi @xRiskLab , I just wanted to follow up on this PR. I know you're likely busy, but I’d appreciate it if you could take a look when you have a moment. Let me know if there’s anything I should clarify or update. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant