You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/v1_migration_guide.rst
+121-19
Original file line number
Diff line number
Diff line change
@@ -53,12 +53,19 @@ Specifies the approach for calculating prediction intervals, especially in advan
53
53
- **v0.9**: Part of ``MapieRegressor``. Configured for the main prediction process.
54
54
- **v1**: Specific to ``CrossConformalRegressor`` and ``JackknifeAfterBootstrapRegressor``, indicating the interval calculation approach (``"base"``, ``"plus"``, or ``"minmax"``).
55
55
56
-
``cv`` (includes ``groups``)
57
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56
+
``cv``
57
+
~~~~~~~
58
58
The ``cv`` parameter manages the cross-validation configuration, accepting either an integer to indicate the number of data splits or a ``BaseCrossValidator`` object for custom data splitting.
59
59
60
60
- **v0.9**: The ``cv`` parameter was included in ``MapieRegressor``, where it handled cross-validation. The option ``cv="prefit"`` was available for models that were already pre-trained.
61
-
- **v1**: The ``cv`` parameter is now only present in ``CrossConformalRegressor``, with the ``prefit`` option removed. Additionally, the ``groups`` parameter was removed from the ``fit`` method, allowing groups to be directly passed to ``cv`` for processing.
61
+
- **v1**: The ``cv`` parameter is now only present in ``CrossConformalRegressor``, with the ``prefit`` option removed.
62
+
63
+
``groups``
64
+
~~~~~~~~~~~
65
+
The ``groups`` parameter is used to specify group labels for cross-validation, ensuring that the same group is not present in both training and calibration sets.
66
+
67
+
- **v0.9**: Passed as a parameter to the ``fit`` method.
68
+
- **v1**: The ``groups`` present is now only present in ``CrossConformalRegressor``. It is passed in the ``.conformalize()`` method instead of the ``.fit()`` method.
62
69
63
70
``prefit``
64
71
~~~~~~~~~~
@@ -81,12 +88,12 @@ Defines additional parameters exclusively for prediction.
81
88
- **v0.9**: Passed additional parameters in a flexible but less explicit manner, sometimes mixed within training configurations.
82
89
- **v1**: Now structured as a dedicated dictionary, ``predict_params``, to be used during calibration (``conformalize`` method) and prediction stages, ensuring no overlap with training parameters.
83
90
84
-
``aggregation_method``
85
-
~~~~~~~~~~~~~~~~~~~~~~
86
-
The ``aggregation_method`` parameter defines how predictions from multiple conformal regressors are aggregated when making point predictions.
The aggregation method and technique for combining predictions in ensemble methods.
87
94
88
95
- **v0.9**: Previously, the ``agg_function`` parameter specified the aggregation method, allowing options such as the mean or median of predictions. This was applicable only when using ensemble methods by setting ``ensemble=True`` in the ``predict`` method.
89
-
- **v1**: The ``agg_function`` parameter has been renamed to ``aggregation_method`` for clarity. It now serves the same purpose in selecting an aggregation technique but is specified at prediction time rather than during class initialization. Additionally, the ``ensemble`` parameter has been removed, as ``aggregation_method`` is relevant only to the ``CrossConformalRegressor`` and ``JackknifeAfterBootstrapRegressor`` classes.
96
+
- **v1**: The ``agg_function`` parameter has been devided into two separate parameters: ``aggregate_predictions`` and ``aggregation_method``. ``aggregate_predictions`` is specific to ``CrossConformalRegressor``, and it specifies how predictions from multiple conformal regressors are aggregated when making point predictions. ``aggregation_method`` is specific to ``JackknifeAfterBootstrapRegressor``, and it specifies the aggregation technique for combining predictions across different bootstrap samples during calibration.
90
97
91
98
``Other parameters``
92
99
~~~~~~~~~~~~~~~~~~~~
@@ -142,15 +149,28 @@ MAPIE v1 introduces two distinct methods for prediction:
142
149
143
150
Below is a side-by-side example of code in MAPIE v0.9 and its equivalent in MAPIE v1 using the new modular classes and methods.
144
151
145
-
MAPIE v0.9 code
146
-
~~~~~~~~~~~~~~~
152
+
Example 1: Split Conformal Prediction
153
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154
+
155
+
Description
156
+
############
157
+
Split conformal prediction is a widely used method for generating prediction intervals, it splits the data into training, calibration, and test sets. The model is trained on the training set, calibrated on the calibration set, and then used to make predictions on the test set. In `MAPIE v1`, the `SplitConformalRegressor` replaces the older `MapieRegressor` with a more modular design and simplified API.
158
+
159
+
MAPIE v0.9 Code
160
+
###############
161
+
162
+
Below is a MAPIE v0.9 code for split conformal prediction in case of pre-fitted models:
147
163
148
164
.. code-block:: python
149
165
150
166
from sklearn.linear_model import LinearRegression
151
167
from mapie.estimator import MapieRegressor
152
168
from mapie.conformity_scores import GammaConformityScore
153
169
from sklearn.model_selection import train_test_split
170
+
from sklearn.datasets import make_regression
171
+
172
+
# Generate synthetic data
173
+
X, y = make_regression(n_samples=100, n_features=2, noise=0.1)
154
174
155
175
# Step 1: Split data
156
176
X_train, X_conf_test, y_train, y_conf_test = train_test_split(X, y, test_size=0.4)
@@ -174,13 +194,19 @@ MAPIE v0.9 code
174
194
prediction_points_v0 = v0.predict(X_test)
175
195
176
196
Equivalent MAPIE v1 code
177
-
~~~~~~~~~~~~~~~~~~~~~~~~
197
+
########################
198
+
199
+
Below is the equivalent MAPIE v1 code for split conformal prediction:
178
200
179
201
.. code-block:: python
180
202
181
203
from sklearn.linear_model import LinearRegression
182
204
from mapie.estimator import SplitConformalRegressor
183
205
from mapie.utils import conf_split
206
+
from sklearn.datasets import make_regression
207
+
208
+
# Generate synthetic data
209
+
X, y = make_regression(n_samples=100, n_features=2, noise=0.1)
184
210
185
211
# Step 1: Split data with conf_split (returns X_train, y_train, X_conf, y_conf, X_test, y_test)
Cross-conformal prediction extends split conformal prediction by using multiple cross-validation folds to improve the efficiency of the prediction intervals. In MAPIE v1, `CrossConformalRegressor`` replaces the older `MapieRegressor`` for this purpose.
240
+
241
+
MAPIE v0.9 code
242
+
###############
243
+
244
+
Below is a MAPIE v0.9 code for cross-conformal prediction:
245
+
246
+
.. code-block:: python
247
+
248
+
from sklearn.ensemble import RandomForestRegressor
249
+
from mapie.estimator import MapieRegressor
250
+
from mapie.conformity_scores import CrossConformalConformityScore
251
+
from sklearn.model_selection import train_test_split
252
+
from sklearn.datasets import make_regression
253
+
254
+
# Generate synthetic data
255
+
X, y = make_regression(n_samples=100, n_features=2, noise=0.1)
256
+
257
+
# Step 1: Split data
258
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4)
259
+
260
+
# Step 2: Train the model on the training set
261
+
regression_model = RandomForestRegressor(
262
+
n_estimators=100,
263
+
max_depth=5
264
+
)
265
+
266
+
# Step 3: Initialize MapieRegressor with the prefit model and cross-conformal conformity score
267
+
v0 = MapieRegressor(
268
+
estimator=regression_model,
269
+
cv=3,
270
+
conformity_score=CrossConformalConformityScore()
271
+
)
272
+
273
+
# Step 4: Fit MAPIE on the calibration set
274
+
v0.fit(X_conf, y_conf)
275
+
276
+
# Step 5: Make predictions with confidence intervals
0 commit comments