@@ -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
0 commit comments