Skip to content

Commit 454cd4e

Browse files
committed
FIX: small issues in plot_cqr_symmetry_difference.py in regression examples
1 parent 4ee6218 commit 454cd4e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

examples/regression/1-quickstart/plot_cqr_symmetry_difference.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from mapie.metrics import regression_coverage_score
1414
from mapie.quantile_regression import MapieQuantileRegressor
1515

16+
random_state = 2
17+
1618
##############################################################################
1719
# We generate a synthetic data.
1820

@@ -22,13 +24,13 @@
2224
alpha = 0.2
2325

2426
# Fit a Gradient Boosting Regressor for quantile regression
25-
quantiles = [0.1, 0.9]
26-
gb_reg = GradientBoostingRegressor(loss="quantile", alpha=quantiles[1])
27-
gb_reg.fit(X, y)
27+
gb_reg = GradientBoostingRegressor(
28+
loss="quantile", alpha=0.5, random_state=random_state
29+
)
2830

2931
# MAPIE Quantile Regressor
3032
mapie_qr = MapieQuantileRegressor(estimator=gb_reg, alpha=alpha)
31-
mapie_qr.fit(X, y)
33+
mapie_qr.fit(X, y, random_state=random_state)
3234
y_pred_sym, y_pis_sym = mapie_qr.predict(X, symmetry=True)
3335
y_pred_asym, y_pis_asym = mapie_qr.predict(X, symmetry=False)
3436
y_qlow = mapie_qr.estimators_[0].predict(X)
@@ -64,7 +66,6 @@
6466
plt.xlabel("x")
6567
plt.ylabel("y")
6668
plt.scatter(X, y, alpha=0.3)
67-
#plt.plot(X_sorted, y_pred_sym_sorted, color="C1")
6869
plt.plot(X_sorted, y_qlow, color="C1")
6970
plt.plot(X_sorted, y_qup, color="C1")
7071
plt.plot(X_sorted, y_pis_sym_sorted[:, 0], color="C1", ls="--")
@@ -86,7 +87,6 @@
8687
plt.xlabel("x")
8788
plt.ylabel("y")
8889
plt.scatter(X, y, alpha=0.3)
89-
#plt.plot(X_sorted, y_pred_asym_sorted, color="C2")
9090
plt.plot(X_sorted, y_qlow, color="C2")
9191
plt.plot(X_sorted, y_qup, color="C2")
9292
plt.plot(X_sorted, y_pis_asym_sorted[:, 0], color="C2", ls="--")
@@ -106,7 +106,9 @@
106106
plt.show()
107107

108108
##############################################################################
109-
# The symmetric intervals (`symmetry=True`) are easier to interpret and
110-
# tend to have higher coverage but might not adapt well to varying
111-
# noise levels. The asymmetric intervals (`symmetry=False`) are more
112-
# flexible and better capture heteroscedasticity but can appear more jagged.
109+
# The symmetric intervals (`symmetry=True`) use a combined set of residuals
110+
# for both bounds, while the asymmetric intervals use distinct residuals for
111+
# each bound, allowing for more flexible and accurate intervals that reflect
112+
# the heteroscedastic nature of the data. The resulting effective coverages
113+
# demonstrate the theoretical guarantee of the target coverage level
114+
# $(1−\alpha)$.

0 commit comments

Comments
 (0)