Skip to content

Binary risk control - implementation batch 1 #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: binary-risk-control
Choose a base branch
from

Conversation

Valentin-Laurent
Copy link
Collaborator

@Valentin-Laurent Valentin-Laurent commented Jul 29, 2025

Context

Implementation of binary classification risk control in its simplest form:

  • Mono-risk
  • Unidimensional lambda (using thresholding on predict_proba)

Content

This PR includes (lists incrementally updated):

Existing risk-control code:

  • Remove useless check on lambda=None in ltt_procedure
  • Remove useless p_values from ltt_procedure outputs
  • Add possibility to pass an array of n_obs to ltt_procedure and subsequent p-values calculations (needed for binary classification). Unit test this behaviour.
  • Fix parametrizing of existing test

New risk-control code:

  • Implement BinaryClassificationRisk class, instances, and related unit test
  • Implement BinaryClassificationController class

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements binary classification risk control in its simplest form, focusing on mono-risk and unidimensional lambda using thresholding on predict_proba. The implementation includes cleanup of existing risk control code and introduction of new binary classification risk control components.

Key changes:

  • Remove unnecessary components from existing LTT procedure (lambda=None check, p_values output)
  • Add support for array-based n_obs in p-value calculations for binary classification scenarios
  • Implement BinaryClassificationRisk class with predefined instances for precision, recall, and accuracy
  • Introduce BinaryClassificationController for threshold-based binary classification risk control

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mapie/control_risk/ltt.py Remove p_values return, lambda=None check, and add array support for n_obs
mapie/control_risk/p_values.py Add array support for n_obs parameter in Hoeffding-Bentkus p-value computation
mapie/risk_control.py Add BinaryClassificationRisk class and predefined risk instances
mapie/risk_control_draft.py Implement BinaryClassificationController with threshold-based risk control
mapie/tests/test_control_risk.py Update tests for LTT changes and add n_obs array testing
mapie/tests/test_risk_control.py Add comprehensive tests for BinaryClassificationRisk instances
mapie/init.py Remove risk_control_draft from exports
Comments suppressed due to low confidence (2)

mapie/tests/test_risk_control.py:848

  • The test should verify the specific condition that leads to None result (effective_sample_size == 0) rather than using a general elif clause. Consider adding an explicit assertion that effective_sample_func returns 0 when result is None.
    elif result is None:

mapie/risk_control_draft.py:18

  • The entire BinaryClassificationController class is marked with pragma: no cover, indicating missing test coverage. This class implements core functionality and should have comprehensive unit tests.
class BinaryClassificationController:  # pragma: no cover

 - Use BinaryClassificationRisk to compute risk
 - Use warning instead of error when risk is not controled. Throw error when predicting
 - Remove useless check on lambda=None in ltt_procedure
 - Remove useless p_values from ltt_procedure outputs
 - Add possibility to pass an array of n_obs to ltt_procedure and subsequent p-values calculations (needed for binary classification)
 - Fix bentkus_p_value calculation
 - Fix and move higher_is_better logic in the same place
 - Implement unit test for BinaryClassificationRiskControl
 - Fix parametrizing of existing test
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