Skip to content

Commit fc0f46a

Browse files
author
Thibault Cordier
committed
FIX: adapt exemple code with new signatures
1 parent 0eb7203 commit fc0f46a

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

examples/classification/1-quickstart/plot_comp_methods_on_2d_dataset.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def plot_scores(
170170
for i, method in enumerate(methods):
171171
conformity_scores = mapie[method].conformity_scores_
172172
n = mapie[method].n_samples_
173-
quantiles = mapie[method].quantiles_
173+
quantiles = mapie[method].conformity_score_function_.quantiles_
174174
plot_scores(alpha, conformity_scores, quantiles, method, axs[i])
175175
plt.show()
176176

@@ -270,7 +270,8 @@ def plot_results(
270270
axs[0].set_xlabel("1 - alpha")
271271
axs[0].set_ylabel("Quantile")
272272
for method in methods:
273-
axs[0].scatter(1 - alpha_, mapie[method].quantiles_, label=method)
273+
quantiles = mapie[method].conformity_score_function_.quantiles_
274+
axs[0].scatter(1 - alpha_, quantiles, label=method)
274275
axs[0].legend()
275276
for method in methods:
276277
axs[1].scatter(1 - alpha_, coverage[method], label=method)

examples/classification/4-tutorials/plot_crossconformal.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@
134134

135135
fig, axs = plt.subplots(1, len(mapies["lac"]), figsize=(20, 4))
136136
for i, (key, mapie) in enumerate(mapies["lac"].items()):
137+
quantiles = mapie.conformity_score_function_.quantiles_[9]
137138
axs[i].set_xlabel("Conformity scores")
138139
axs[i].hist(mapie.conformity_scores_)
139-
axs[i].axvline(mapie.quantiles_[9], ls="--", color="k")
140-
axs[i].set_title(f"split={key}\nquantile={mapie.quantiles_[9]:.3f}")
140+
axs[i].axvline(quantiles, ls="--", color="k")
141+
axs[i].set_title(f"split={key}\nquantile={quantiles:.3f}")
141142
plt.suptitle(
142143
"Distribution of scores on each calibration fold for the "
143144
f"{methods[0]} method"

examples/classification/4-tutorials/plot_main-tutorial-binary-classification.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def plot_scores(
188188

189189
fig, axs = plt.subplots(1, 1, figsize=(10, 5))
190190
conformity_scores = mapie_clf.conformity_scores_
191-
quantiles = mapie_clf.quantiles_
191+
quantiles = mapie_clf.conformity_score_function_.quantiles_
192192
plot_scores(alpha, conformity_scores, quantiles, 'lac', axs)
193193
plt.show()
194194

@@ -309,10 +309,11 @@ def plot_results(
309309

310310

311311
def plot_coverages_widths(alpha, coverage, width, method):
312+
quantiles = mapie_clf.conformity_score_function_.quantiles_
312313
_, axs = plt.subplots(1, 3, figsize=(15, 5))
313314
axs[0].set_xlabel("1 - alpha")
314315
axs[0].set_ylabel("Quantile")
315-
axs[0].scatter(1 - alpha, mapie_clf.quantiles_, label=method)
316+
axs[0].scatter(1 - alpha, quantiles, label=method)
316317
axs[0].legend()
317318
axs[1].scatter(1 - alpha, coverage, label=method)
318319
axs[1].set_xlabel("1 - alpha")

examples/classification/4-tutorials/plot_main-tutorial-classification.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def plot_scores(n, alphas, scores, quantiles):
148148

149149
scores = mapie_score.conformity_scores_
150150
n = len(mapie_score.conformity_scores_)
151-
quantiles = mapie_score.quantiles_
151+
quantiles = mapie_score.conformity_score_function_.quantiles_
152152
plot_scores(n, alpha, scores, quantiles)
153153

154154
##############################################################################

examples/regression/2-advanced-analysis/plot_conformal_predictive_distribution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_cumulative_distribution_function(self, X):
7171
y_pred = self.predict(X)
7272
cs = self.conformity_scores_[~np.isnan(self.conformity_scores_)]
7373
res = self.conformity_score_function_.get_estimation_distribution(
74-
X, y_pred.reshape((-1, 1)), cs
74+
y_pred.reshape((-1, 1)), cs, X=X
7575
)
7676
return res
7777

mapie/classification.py

-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ class MapieClassifier(BaseEstimator, ClassifierMixin):
146146
conformity_scores_: ArrayLike of shape (n_samples_train)
147147
The conformity scores used to calibrate the prediction sets.
148148
149-
quantiles_: ArrayLike of shape (n_alpha)
150-
The quantiles estimated from ``conformity_scores_`` and alpha values.
151-
152149
References
153150
----------
154151
[1] Mauricio Sadinle, Jing Lei, and Larry Wasserman.

mapie/conformity_scores/classification.py

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class BaseClassificationScore(BaseConformityScore, metaclass=ABCMeta):
3131
It should be specified if ``consistency_check==True``.
3232
3333
By default, it is defined by the default precision.
34+
35+
Attributes
36+
----------
37+
quantiles_: ArrayLike of shape (n_alpha)
38+
The quantiles estimated from ``conformity_scores_`` and alpha values.
3439
"""
3540

3641
def __init__(

0 commit comments

Comments
 (0)