@@ -45,7 +45,7 @@ Prediction intervals output by **MAPIE** encompass both aleatoric and epistemic
4545
4646Python 3.7+
4747
48- **MAPIE ** stands on the shoulders of giant .
48+ **MAPIE ** stands on the shoulders of giants .
4949
5050Its only internal dependency is `scikit-learn <https://scikit-learn.org/stable/ >`_.
5151
@@ -89,11 +89,13 @@ and two standard deviations from the mean.
8989.. code :: python
9090
9191 from mapie.estimators import MapieRegressor
92- mapie = MapieRegressor(regressor)
92+ alpha = [0.05 , 0.32 ]
93+ mapie = MapieRegressor(regressor, alpha = alpha)
9394 mapie.fit(X, y)
9495 y_preds = mapie.predict(X)
9596
9697
98+
9799 MAPIE returns a ``np.ndarray `` of shape (n_samples, 3, len(alpha)) giving the predictions,
98100as well as the lower and upper bounds of the prediction intervals for the target quantile
99101for each desired alpha value.
@@ -103,14 +105,18 @@ The estimated prediction intervals can then be plotted as follows.
103105
104106 from matplotlib import pyplot as plt
105107 from mapie.metrics import coverage_score
106- plt.xlabel(' x ' )
107- plt.ylabel(' y ' )
108+ plt.xlabel(" x " )
109+ plt.ylabel(" y " )
108110 plt.scatter(X, y, alpha = 0.3 )
109- plt.plot(X, y_preds[:, 0 ], color = ' C1 ' )
111+ plt.plot(X, y_preds[:, 0 , 0 ], color = " C1 " )
110112 order = np.argsort(X[:, 0 ])
111- plt.fill_between(X[order].ravel(), y_preds[:, 1 ][order], y_preds[:, 2 ][order], alpha = 0.3 )
113+ plt.plot(X[order], y_preds[order][:, 1 , 1 ], color = " C1" , ls = " --" )
114+ plt.plot(X[order], y_preds[order][:, 2 , 1 ], color = " C1" , ls = " --" )
115+ plt.fill_between(X[order].ravel(), y_preds[:, 1 , 0 ][order].ravel(), y_preds[:, 2 , 0 ][order].ravel(), alpha = 0.2 )
116+ coverage_scores = [coverage_score(y, y_preds[:, 1 , i], y_preds[:, 2 , i]) for i, _ in enumerate (alpha)]
112117 plt.title(
113- f " Target coverage = 0.9; Effective coverage = { coverage_score(y, y_preds[:, 1 ], y_preds[:, 2 ])} "
118+ f " Target and effective coverages for alpha= { alpha[0 ]:.2f } : ( { 1 - alpha[0 ]:.3f } , { coverage_scores[0 ]:.3f } ) \n " +
119+ f " Target and effective coverages for alpha= { alpha[1 ]:.2f } : ( { 1 - alpha[1 ]:.3f } , { coverage_scores[1 ]:.3f } ) "
114120 )
115121 plt.show()
116122
0 commit comments