-
Notifications
You must be signed in to change notification settings - Fork 126
FEAT: Venn-ABERS calibrator for binary classification is added. #736
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
base: master
Are you sure you want to change the base?
Conversation
Hello @dimoibiehg, thank you so much for this high-quality PR. MAPIE core devs are on holidays, we'll be back to our keyboards by the end of August, and are willing to merge your work. Few remarks came to my mind after a quick read, feel free to proceed in the meantime if you'd like:
Thanks again, looking forward to reviewing this in more detail soon. In the meantime, let’s give Copilot a bit of work, it sometimes catches interesting things. |
There was a problem hiding this 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 Venn-ABERS calibration for binary classification problems in MAPIE, providing a new calibration method based on the Inductive Venn-ABERS Predictors (IVAP) algorithm. The implementation adds the VennABERSCalibrator
class which wraps the algorithm described in the Vovk et al. paper.
Key changes include:
- Addition of a complete VennABERSCalibrator class with fit and predict methods
- Implementation of the core Venn-ABERS algorithms (Algorithms 1-4 from the paper)
- Comprehensive test suite covering initialization, parameter validation, and calibration functionality
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
File | Description |
---|---|
mapie/calibration.py | Adds the complete VennABERSCalibrator class implementation with all core algorithms |
mapie/tests/test_calibration.py | Adds comprehensive test suite for the new calibrator including edge cases and validation |
HISTORY.rst | Documents the new feature addition |
AUTHORS.rst | Adds the contributor credit |
|
||
valid_inputs = ["binary"] | ||
|
||
calibration_points_: list[Tuple[float, Union[int, float]]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation should use List
from typing
instead of the built-in list
for consistency with other type annotations in the codebase and better compatibility with older Python versions.
calibration_points_: list[Tuple[float, Union[int, float]]] | |
calibration_points_: List[Tuple[float, Union[int, float]]] |
Copilot uses AI. Check for mistakes.
+ (", ").join(self.valid_inputs) + "." | ||
) | ||
|
||
def _prepare_data(self, calibr_points: list[Tuple[float, float]]) -> Tuple: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation should use List
from typing
instead of the built-in list
for consistency with other type annotations in the codebase.
def _prepare_data(self, calibr_points: list[Tuple[float, float]]) -> Tuple: | |
def _prepare_data(self, calibr_points: List[Tuple[float, float]]) -> Tuple: |
Copilot uses AI. Check for mistakes.
|
||
return y_prime, y_csd, x_prime, pts_unique, k_prime | ||
|
||
def _algorithm1(self, P: Dict, k_prime: int) -> list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type annotation should use List
from typing
instead of the built-in list
for consistency with other type annotations in the codebase.
def _algorithm1(self, P: Dict, k_prime: int) -> list: | |
def _algorithm1(self, P: Dict, k_prime: int) -> List: |
Copilot uses AI. Check for mistakes.
S.append(P[i]) | ||
return S | ||
|
||
def _algorithm2(self, P: Dict, S: list, k_prime: int) -> NDArray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter type annotation should use List
from typing
instead of the built-in list
for consistency with other type annotations in the codebase.
def _algorithm2(self, P: Dict, S: list, k_prime: int) -> NDArray: | |
def _algorithm2(self, P: Dict, S: List, k_prime: int) -> NDArray: |
Copilot uses AI. Check for mistakes.
|
||
return F1 | ||
|
||
def _algorithm3(self, P: Dict, k_prime: int) -> list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type annotation should use List
from typing
instead of the built-in list
for consistency with other type annotations in the codebase.
def _algorithm3(self, P: Dict, k_prime: int) -> list: | |
def _algorithm3(self, P: Dict, k_prime: int) -> List: |
Copilot uses AI. Check for mistakes.
|
||
return S | ||
|
||
def _algorithm4(self, P: Dict, S: list, k_prime: int) -> NDArray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter type annotation should use List
from typing
instead of the built-in list
for consistency with other type annotations in the codebase.
def _algorithm4(self, P: Dict, S: list, k_prime: int) -> NDArray: | |
def _algorithm4(self, P: Dict, S: List, k_prime: int) -> NDArray: |
Copilot uses AI. Check for mistakes.
pos1 = np.searchsorted(pts_unique[:-1], test_objects, side='right') + 1 | ||
return F0[pos0], F1[pos1] | ||
|
||
def _scores_to_multi_probs(self, calibr_points: list[Tuple[float, float]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter type annotation should use List
from typing
instead of the built-in list
for consistency with other type annotations in the codebase.
def _scores_to_multi_probs(self, calibr_points: list[Tuple[float, float]], | |
def _scores_to_multi_probs(self, calibr_points: List[Tuple[float, float]], |
Copilot uses AI. Check for mistakes.
In addition to my previous comment regarding testing the correctness of implementation, here's another implementation of Venn-Abers, validated by Vovk at COPA 2023 : https://github.com/ip200/venn-abers |
This is a much more complete implementation, including multi-class classification. |
If you're willing to, it would be definitely worth it yes, because this repository seems very reliable in terms of correctness of implementation. Because the scope would be larger, maybe starting with a reduced scope (if possible/relevant) is a good idea. In any case, we have to make sure we actually have the right to re-use the code. But seems that this is OK: both repos are under MIT license, which according to french Wikipedia allows sub-licensing (provided we mention the original licence and copyright). |
Description
Venn-ABERS calibration for binary classification problems.
Implements the Inductive Venn-ABERS Predictors (IVAP) algorithm described in:
"Large-scale probabilistic prediction with and without validity guarantees"
by Vovk et al. (https://arxiv.org/pdf/1511.00213.pdf).
This is a MAPIE wrapper for
the implementation in https://github.com/ptocca/VennABERS/.
Note that VennABERSCalibrator uses its own specific calibration algorithm.
Type of change
Please remove options that are irrelevant.
How Has This Been Tested?
A list of tests has been implemented and added to the end of
test_calibration.py
.Checklist
make lint
make type-check
make tests
make coverage
make doc
make doctest