Skip to content

Commit e287463

Browse files
authored
Merge pull request #53 from simai-ml/small_changes
small changes
2 parents d9c2791 + 78105ad commit e287463

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

doc/quick_start.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,30 @@ The estimated prediction intervals can then be plotted as follows.
6666
6767
from matplotlib import pyplot as plt
6868
from mapie.metrics import coverage_score
69+
70+
coverage_scores = [
71+
coverage_score(y, y_preds[:, 1, i], y_preds[:, 2, i])
72+
for i, _ in enumerate(alpha)
73+
]
74+
6975
plt.xlabel("x")
7076
plt.ylabel("y")
7177
plt.scatter(X, y, alpha=0.3)
7278
plt.plot(X, y_preds[:, 0, 0], color="C1")
7379
order = np.argsort(X[:, 0])
7480
plt.plot(X[order], y_preds[order][:, 1, 1], color="C1", ls="--")
7581
plt.plot(X[order], y_preds[order][:, 2, 1], color="C1", ls="--")
76-
plt.fill_between(X[order].ravel(), y_preds[:, 1, 0][order].ravel(), y_preds[:, 2, 0][order].ravel(), alpha=0.2)
77-
coverage_scores = [coverage_score(y, y_preds[:, 1, i], y_preds[:, 2, i]) for i, _ in enumerate(alpha)]
82+
plt.fill_between(
83+
X[order].ravel(),
84+
y_preds[:, 1, 0][order].ravel(),
85+
y_preds[:, 2, 0][order].ravel(),
86+
alpha=0.2
87+
)
7888
plt.title(
79-
f"Target and effective coverages for alpha={alpha[0]:.2f}: ({1-alpha[0]:.3f}, {coverage_scores[0]:.3f})\n" +
80-
f"Target and effective coverages for alpha={alpha[1]:.2f}: ({1-alpha[1]:.3f}, {coverage_scores[1]:.3f})"
89+
f"Target and effective coverages for "
90+
f"alpha={alpha[0]:.2f}: ({1-alpha[0]:.3f}, {coverage_scores[0]:.3f})\n"
91+
f"Target and effective coverages for "
92+
f"alpha={alpha[1]:.2f}: ({1-alpha[1]:.3f}, {coverage_scores[1]:.3f})"
8193
)
8294
plt.show()
8395

examples/plot_toy_model.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
mapie.fit(X, y)
2323
y_preds = mapie.predict(X)
2424

25+
coverage_scores = [
26+
coverage_score(y, y_preds[:, 1, i], y_preds[:, 2, i])
27+
for i, _ in enumerate(alpha)
28+
]
29+
2530
plt.xlabel("x")
2631
plt.ylabel("y")
2732
plt.scatter(X, y, alpha=0.3)
@@ -35,10 +40,6 @@
3540
y_preds[:, 2, 0][order].ravel(),
3641
alpha=0.2
3742
)
38-
coverage_scores = [
39-
coverage_score(y, y_preds[:, 1, i], y_preds[:, 2, i])
40-
for i, _ in enumerate(alpha)
41-
]
4243
plt.title(
4344
f"Target and effective coverages for "
4445
f"alpha={alpha[0]:.2f}: ({1-alpha[0]:.3f}, {coverage_scores[0]:.3f})\n"

mapie/estimators.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ def _check_cv(
293293
if cv >= 2:
294294
return KFold(n_splits=cv)
295295
if (
296-
isinstance(cv, KFold) or
297-
isinstance(cv, LeaveOneOut) or
298-
cv == "prefit"
296+
isinstance(cv, KFold)
297+
or isinstance(cv, LeaveOneOut)
298+
or cv == "prefit"
299299
):
300300
return cv
301301
raise ValueError(
@@ -441,12 +441,11 @@ def _fit_and_predict_oof_model(
441441
"""
442442
X_train, y_train, X_val = X[train_index], y[train_index], X[val_index]
443443
if sample_weight is None:
444-
sample_weight_train = None
444+
estimator = fit_estimator(estimator, X_train, y_train)
445445
else:
446-
sample_weight_train = sample_weight[train_index]
447-
estimator = fit_estimator(
448-
estimator, X_train, y_train, sample_weight_train
449-
)
446+
estimator = fit_estimator(
447+
estimator, X_train, y_train, sample_weight[train_index]
448+
)
450449
y_pred = estimator.predict(X_val)
451450
val_id = np.full_like(y_pred, k)
452451
return estimator, y_pred, val_id, val_index
@@ -555,7 +554,7 @@ def predict(self, X: ArrayLike) -> np.ndarray:
555554
"""
556555
# Checks
557556
check_is_fitted(
558-
self,
557+
self,
559558
[
560559
"n_features_in_",
561560
"single_estimator_",

0 commit comments

Comments
 (0)