|
35 | 35 |
|
36 | 36 |
|
37 | 37 | ############################################################################## |
38 | | -# 1. Create the noisy dataset with 10 groups, each of those groups having |
39 | | -# a different level of noise. |
40 | | -# ------------------------------------------------------------------- |
| 38 | +# 1. Create the noisy dataset |
| 39 | +# ----------------------------- |
| 40 | +# We create a dataset with 10 groups, each of those groups having a different |
| 41 | +# level of noise. |
41 | 42 |
|
42 | 43 |
|
43 | 44 | n_points = 100000 |
|
86 | 87 |
|
87 | 88 | ############################################################################## |
88 | 89 | # 2. Split the dataset into a training set, a calibration set, and a test set. |
89 | | - |
| 90 | +# ----------------------------- |
90 | 91 |
|
91 | 92 | X_train_temp, X_test, y_train_temp, y_test = train_test_split( |
92 | 93 | X, y, test_size=0.2, random_state=0 |
|
118 | 119 |
|
119 | 120 | ############################################################################## |
120 | 121 | # 3. Fit a random forest regressor on the training set. |
121 | | - |
| 122 | +# ----------------------------- |
122 | 123 |
|
123 | 124 | rf = RandomForestRegressor(n_estimators=100) |
124 | 125 | rf.fit(X_train, y_train) |
125 | 126 |
|
126 | 127 |
|
127 | 128 | ############################################################################## |
128 | 129 | # 4. Fit a MapieRegressor and a MondrianCP on the calibration set. |
129 | | - |
| 130 | +# ----------------------------- |
130 | 131 |
|
131 | 132 | mapie_regressor = MapieRegressor(rf, cv="prefit") |
132 | 133 | mondrian_regressor = MondrianCP(MapieRegressor(rf, cv="prefit")) |
|
136 | 137 |
|
137 | 138 | ############################################################################## |
138 | 139 | # 5. Predict the prediction intervals on the test set with both methods. |
139 | | - |
| 140 | +# ----------------------------- |
140 | 141 |
|
141 | 142 | _, y_pss_split = mapie_regressor.predict(X_test, alpha=.1) |
142 | 143 | _, y_pss_mondrian = mondrian_regressor.predict( |
|
146 | 147 |
|
147 | 148 | ############################################################################## |
148 | 149 | # 6. Compare the coverage by partition, plot both methods side by side. |
149 | | - |
| 150 | +# ----------------------------- |
150 | 151 |
|
151 | 152 | coverages = {} |
152 | 153 | for group in np.unique(partition_test): |
|
0 commit comments