Skip to content
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

Building of Ensemble Classifier from MapieClassifier #445

Merged
merged 42 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0d0dd8d
Add refacto Ensemble Classifier
BaptisteCalot May 14, 2024
b7ec890
Split Ensemble Classifier and Ensemble Regressor into 2 files
BaptisteCalot May 15, 2024
d0bbf06
Including previous PR
BaptisteCalot May 15, 2024
19510fb
delete print in the code
BaptisteCalot May 15, 2024
05f282e
Add documentation in functions
BaptisteCalot May 15, 2024
c70cb21
Modification of typo
BaptisteCalot May 15, 2024
3d49d2d
Modification of documentation
BaptisteCalot May 15, 2024
be25333
Typo
BaptisteCalot May 15, 2024
ac3cd46
Typo
BaptisteCalot May 15, 2024
722728b
Modification of unit tests
BaptisteCalot May 15, 2024
ad877fd
Modification of unit tests
BaptisteCalot May 15, 2024
75bf335
Fix of unit test: test_pred_loof_isnan
BaptisteCalot May 15, 2024
e9c3116
UPD: clean code
thibaultcordier May 16, 2024
381b797
UPD: change name file and reduce line changes
thibaultcordier May 16, 2024
905c3da
UPD: structure code reg vs. class and upd tests
thibaultcordier May 16, 2024
c0ce683
FIX: solve last tests
thibaultcordier May 17, 2024
386a238
FIX: add init files
thibaultcordier May 17, 2024
dc3d55d
UPD: remove useless methods
thibaultcordier May 17, 2024
fccc0e3
FIX: solve last test
thibaultcordier May 22, 2024
4419d5d
Merge branch 'scikit-learn-contrib:master' into master
BaptisteCalot May 30, 2024
ff9b3c1
FIX some type-check
BaptisteCalot May 30, 2024
d31a65a
FIX: fix typing
vincentblot28 May 30, 2024
e4da31e
Fix : solve linting
BaptisteCalot May 30, 2024
fc62532
FIX: remove useless file
thibaultcordier May 30, 2024
523d06a
Add documentation
BaptisteCalot Jun 3, 2024
c332d27
FIX: remove output expression
thibaultcordier Jun 24, 2024
09628f3
FIX: clean code to lint and type-check errors
thibaultcordier Jun 25, 2024
d6ed656
FIX: move check function to avoid circular import
thibaultcordier Jun 25, 2024
6dc84d9
Merge branch 'master' into master
thibaultcordier Jun 25, 2024
2ab2487
FIX: correct function import
thibaultcordier Jun 25, 2024
630ca65
FIX: correct functino import path
thibaultcordier Jun 25, 2024
41af001
FIX: correct function import path
thibaultcordier Jun 25, 2024
40731a9
UPD: remove useless cast
thibaultcordier Jun 25, 2024
1d978ce
FIX: conserve n_samples attribute
thibaultcordier Jun 25, 2024
56c1a25
UPD: docstring + improved split managemenent + extension of tests to …
thibaultcordier Jun 26, 2024
eb7ad23
FIX: wrong dict name
thibaultcordier Jun 26, 2024
414b6bc
FIX: extend tests to all methods
thibaultcordier Jun 26, 2024
28f782f
FIX: add previous method exclusion
thibaultcordier Jun 26, 2024
42409c0
UPD: add raps_rand_split test + more comments to explain which tests …
thibaultcordier Jun 28, 2024
dd4dd9d
FIX: lint error
thibaultcordier Jun 29, 2024
f1e4899
UPD: label encoder standalone method
thibaultcordier Jun 29, 2024
6bbb59c
UPD: add nan value in test
thibaultcordier Jul 1, 2024
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
503 changes: 219 additions & 284 deletions mapie/classification.py

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions mapie/conformity_scores/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import Optional

from .conformity_scores import ConformityScore
from .residual_conformity_scores import AbsoluteConformityScore


def check_conformity_score(
conformity_score: Optional[ConformityScore],
sym: bool = True,
) -> ConformityScore:
"""
Check parameter ``conformity_score``.

Raises
------
ValueError
If parameter is not valid.

Examples
--------
>>> from mapie.conformity_scores.checks import check_conformity_score
>>> try:
... check_conformity_score(1)
... except Exception as exception:
... print(exception)
...
Invalid conformity_score argument.
Must be None or a ConformityScore instance.
"""
if conformity_score is None:
return AbsoluteConformityScore(sym=sym)
elif isinstance(conformity_score, ConformityScore):
return conformity_score
else:
raise ValueError(
"Invalid conformity_score argument.\n"
"Must be None or a ConformityScore instance."
)
8 changes: 4 additions & 4 deletions mapie/conformity_scores/conformity_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from mapie._compatibility import np_nanquantile
from mapie._typing import ArrayLike, NDArray
from mapie.estimator.interface import EnsembleEstimator
from mapie.estimator.regressor import EnsembleRegressor


class ConformityScore(metaclass=ABCMeta):
Expand Down Expand Up @@ -338,7 +338,7 @@ def _beta_optimize(
def get_bounds(
self,
X: ArrayLike,
estimator: EnsembleEstimator,
estimator: EnsembleRegressor,
conformity_scores: NDArray,
alpha_np: NDArray,
ensemble: bool = False,
Expand All @@ -348,14 +348,14 @@ def get_bounds(
) -> Tuple[NDArray, NDArray, NDArray]:
"""
Compute bounds of the prediction intervals from the observed values,
the estimator of type ``EnsembleEstimator`` and the conformity scores.
the estimator of type ``EnsembleRegressor`` and the conformity scores.

Parameters
----------
X: ArrayLike of shape (n_samples, n_features)
Observed feature values.

estimator: EnsembleEstimator
estimator: EnsembleRegressor
Estimator that is fitted to predict y from X.

conformity_scores: ArrayLike of shape (n_samples,)
Expand Down
9 changes: 9 additions & 0 deletions mapie/estimator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .interface import EnsembleEstimator
from .regressor import EnsembleRegressor
from .classifier import EnsembleClassifier

__all__ = [
"EnsembleEstimator",
"EnsembleRegressor",
"EnsembleClassifier",
]
Loading
Loading