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

ENH: externalize MapieClassifier methods into several non-conformity scores #476

Merged
merged 46 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d3bcba5
UPD: factorize MapieClassifier methods into several non-conformity sc…
Jul 1, 2024
0eb7203
FIX: path access in test doctring
Jul 1, 2024
fc0f46a
FIX: adapt exemple code with new signatures
Jul 1, 2024
f064cc9
UPD: check tests for additional parameters in residual normalized score
Jul 2, 2024
a9c03fd
UPD: typing and doctring in score classes
Jul 2, 2024
7f791dd
UPD: use y_enc as additional parameters to conserve label encoding
Jul 2, 2024
1b99529
UPD: change greater equal to less equal
Jul 2, 2024
e588a3e
UPD: docstring to explain parameters of get_sets
Jul 2, 2024
8832a2e
UPD: remove useless methods et attributes (estimation distribution) f…
Jul 3, 2024
8fa2474
UPD: decompose APS into Naive, APS and RAPS + new abtract methods for…
Jul 3, 2024
c79d6e5
UPD: improve docstring of score classes
Jul 3, 2024
59586a9
UPD: refacto changes in history file
Jul 3, 2024
7d053b7
UPD: add missing attributes + keep quantiles_ attribute
Jul 4, 2024
15b31ff
UPD: remove obsolete 'method' attribute and methods in conformity score
Jul 4, 2024
ee89b53
UPD: reduce doctring
Jul 4, 2024
d9e4989
UPD: change method name
Jul 4, 2024
115c080
DOC: change docstring and useless cast
Jul 5, 2024
64973c0
UPD: remove useless cast + reformat typing
Jul 5, 2024
cdc2716
FIX: float conversion removed
Jul 5, 2024
a8d47e5
UPD: move methods relative to aps, from naive to aps
Jul 5, 2024
2f0ed14
UPD: move get_true_label_cumsum_proba to class method
Jul 5, 2024
0a5ac6e
UPD: add test wrong method in conformity score
Jul 5, 2024
1f916f3
FIX: add missing docstring
Jul 5, 2024
17cfbca
UPD: change default attribute as done in MapieRegressor
Jul 5, 2024
031a8d4
UPD: manage class method with conflict warning
Jul 11, 2024
b1b425e
UPD: reorganize conformity score tests
Jul 11, 2024
5fa0fee
UPD: corrected doctring + comments + minor corrections
Jul 11, 2024
d2cf443
UPD: move split data into conformity score + side effect changes
Jul 12, 2024
ba8021b
FIx: type-check casting
Jul 12, 2024
a2f022c
UPD: add attributes in doctring
Jul 12, 2024
3eb40eb
UPD: add description in tests
Jul 12, 2024
2e0171b
UPD: add all conformity scores to test + test same results with metho…
Jul 12, 2024
e92a713
UPD: doctring parameters
Jul 12, 2024
c3fee46
UPD: move dict at the top of file
Jul 12, 2024
933d4d9
UPD: add all check tests when parameters are wrong
Jul 12, 2024
a096b51
UPD: add deprecated value check
Jul 15, 2024
7b64f6f
UPD: short value check command
Jul 15, 2024
262a96a
FIX: unhashable list
Jul 15, 2024
1e0b66c
UPD: set_external_attributes common method
Jul 15, 2024
e505a22
UPD: change with correct conformity score name
Jul 16, 2024
04e52d4
UPD: change class and method names
Jul 16, 2024
b724c35
FIX: line too long
Jul 16, 2024
ebf107a
UPD: move check cv - cs function
Jul 16, 2024
c3d9025
FIX: typo in docstring and variable names
Jul 16, 2024
d7b4847
UPD: change interval to set
Jul 16, 2024
4c97a00
UPD: documentation with score api
Jul 17, 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
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ History
0.8.x (2024-xx-xx)
------------------

* Extend `ConformityScore` to support regression (with `BaseRegressionScore`) and to support classification (with `BaseClassificationScore`)
* Extend `EnsembleEstimator` to support regression (with `EnsembleRegressor`) and to support classification (with `EnsembleClassifier`)
* Refactor `MapieClassifier` by separating the handling of the `MapieClassifier` estimator into a new class called `EnsembleClassifier`
* Refactor `MapieClassifier` by separating the handling of the `MapieClassifier` conformity score into a new class called `BaseClassificationScore`
* Add severals non-conformity scores for classification (`LAC`, `APS`, `RAPS`, `TopK`) based on `BaseClassificationScore`
* Transfer the logic of classification methods into the non-conformity score classes (`LAC`, `APS`, `RAPS`, `TopK`)
* Extend the classification strategy definition by supporting `method` and `conformity_score` attributes
* Building unit tests for different `Subsample` and `BlockBooststrap` instances
* Change the sign of C_k in the `Kolmogorov-Smirnov` test documentation
* Building a training set with a fraction between 0 and 1 with `n_samples` attribute when using `split` method from `Subsample` class.
Expand Down
5 changes: 5 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ Conformity scores
:toctree: generated/
:template: class.rst

conformity_scores.BaseRegressionScore
conformity_scores.AbsoluteConformityScore
conformity_scores.GammaConformityScore
conformity_scores.ResidualNormalisedScore
conformity_scores.BaseClassificationScore
conformity_scores.LAC
conformity_scores.APS
conformity_scores.TopK

Resampling
==========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def plot_scores(
for i, method in enumerate(methods):
conformity_scores = mapie[method].conformity_scores_
n = mapie[method].n_samples_
quantiles = mapie[method].quantiles_
quantiles = mapie[method].conformity_score_function_.quantiles_
plot_scores(alpha, conformity_scores, quantiles, method, axs[i])
plt.show()

Expand Down Expand Up @@ -270,7 +270,8 @@ def plot_results(
axs[0].set_xlabel("1 - alpha")
axs[0].set_ylabel("Quantile")
for method in methods:
axs[0].scatter(1 - alpha_, mapie[method].quantiles_, label=method)
quantiles = mapie[method].conformity_score_function_.quantiles_
axs[0].scatter(1 - alpha_, quantiles, label=method)
axs[0].legend()
for method in methods:
axs[1].scatter(1 - alpha_, coverage[method], label=method)
Expand Down
5 changes: 3 additions & 2 deletions examples/classification/4-tutorials/plot_crossconformal.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@

fig, axs = plt.subplots(1, len(mapies["lac"]), figsize=(20, 4))
for i, (key, mapie) in enumerate(mapies["lac"].items()):
quantiles = mapie.conformity_score_function_.quantiles_[9]
axs[i].set_xlabel("Conformity scores")
axs[i].hist(mapie.conformity_scores_)
axs[i].axvline(mapie.quantiles_[9], ls="--", color="k")
axs[i].set_title(f"split={key}\nquantile={mapie.quantiles_[9]:.3f}")
axs[i].axvline(quantiles, ls="--", color="k")
axs[i].set_title(f"split={key}\nquantile={quantiles:.3f}")
plt.suptitle(
"Distribution of scores on each calibration fold for the "
f"{methods[0]} method"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def plot_scores(

fig, axs = plt.subplots(1, 1, figsize=(10, 5))
conformity_scores = mapie_clf.conformity_scores_
quantiles = mapie_clf.quantiles_
quantiles = mapie_clf.conformity_score_function_.quantiles_
plot_scores(alpha, conformity_scores, quantiles, 'lac', axs)
plt.show()

Expand Down Expand Up @@ -309,10 +309,11 @@ def plot_results(


def plot_coverages_widths(alpha, coverage, width, method):
quantiles = mapie_clf.conformity_score_function_.quantiles_
_, axs = plt.subplots(1, 3, figsize=(15, 5))
axs[0].set_xlabel("1 - alpha")
axs[0].set_ylabel("Quantile")
axs[0].scatter(1 - alpha, mapie_clf.quantiles_, label=method)
axs[0].scatter(1 - alpha, quantiles, label=method)
axs[0].legend()
axs[1].scatter(1 - alpha, coverage, label=method)
axs[1].set_xlabel("1 - alpha")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def plot_scores(n, alphas, scores, quantiles):

scores = mapie_score.conformity_scores_
n = len(mapie_score.conformity_scores_)
quantiles = mapie_score.quantiles_
quantiles = mapie_score.conformity_score_function_.quantiles_
plot_scores(n, alpha, scores, quantiles)

##############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_cumulative_distribution_function(self, X):
y_pred = self.predict(X)
cs = self.conformity_scores_[~np.isnan(self.conformity_scores_)]
res = self.conformity_score_function_.get_estimation_distribution(
X, y_pred.reshape((-1, 1)), cs
y_pred.reshape((-1, 1)), cs, X=X
)
return res

Expand Down
2 changes: 1 addition & 1 deletion mapie/_machine_precision.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np

EPSILON = np.finfo(np.float64).eps
EPSILON = np.float64(1e-8)
LacombeLouis marked this conversation as resolved.
Show resolved Hide resolved

__all__ = ["EPSILON"]
Loading
Loading