Skip to content

Commit 6cf7058

Browse files
committed
Fix typo and links
1 parent 83ee2cc commit 6cf7058

9 files changed

+66
-82
lines changed

examples/regression/1-quickstart/plot_ts-tutorial.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
========================
55
66
In this tutorial we describe how to use
7-
:class:`~mapie.time_series_regression.MapieTimeSeriesRegressor`
7+
:class:`~mapie.regression.MapieTimeSeriesRegressor`
88
to estimate prediction intervals associated with time series forecast.
99
1010
Here, we use the Victoria electricity demand dataset used in the book
@@ -24,7 +24,8 @@
2424
the EnbPI method.
2525
2626
As its parent class :class:`~MapieRegressor`,
27-
:class:`~MapieTimeSeriesRegressor` has two main arguments : "cv", and "method".
27+
:class:`~mapie.regression.MapieTimeSeriesRegressor` has two main arguments :
28+
"cv", and "method".
2829
In order to implement EnbPI, "method" must be set to "enbpi" (the default
2930
value) while "cv" must be set to the :class:`~mapie.subsample.BlockBootstrap`
3031
class that block bootstraps the training set.
@@ -34,8 +35,8 @@ class that block bootstraps the training set.
3435
The EnbPI method allows you update the residuals during the prediction,
3536
each time new observations are available so that the deterioration of
3637
predictions, or the increase of noise level, can be dynamically taken into
37-
account. It can be done with :class:`~MapieTimeSeriesRegressor` through
38-
the ``partial_fit`` class method called at every step.
38+
account. It can be done with :class:`~mapie.regression.MapieTimeSeriesRegressor`
39+
through the ``partial_fit`` class method called at every step.
3940
4041
4142
The ACI strategy allows you to adapt the conformal inference

examples/regression/2-advanced-analysis/plot-coverage-width-based-criterion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:class:`~mapie.metrics` is used to estimate the coverage width
1111
based criterion of 1D homoscedastic data using different strategies.
1212
The coverage width based criterion is computed with the function
13-
:func:`~mapie.metrics.coverage_width_based()`
13+
:func:`~mapie.metrics.coverage_width_based`
1414
"""
1515

1616
import os

examples/regression/2-advanced-analysis/plot_conditional_coverage.py

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -186,34 +186,28 @@ def sin_with_controlled_noise(
186186
print(estimated_cond_cov)
187187

188188
##############################################################################
189-
# We can see here that the global coverage is approximately the same for
190-
# all methods. What we want to understand is : "Are these methods good
191-
# adaptive conformal methods ?". For this we have the two metrics
189+
# The global coverage is similar for all methods. To determine if these
190+
# methods are good adaptive conformal methods, we use two metrics:
192191
# :func:`~mapie.metrics.regression_ssc_score` and :func:`~mapie.metrics.hsic`.
193-
# - SSC (Size Stratified Coverage) is the maximum violation of the coverage :
194-
# the intervals are grouped by width and the coverage is computed for each
195-
# group. The lower coverage is the maximum coverage violation. An adaptive
196-
# method is one where this maximum violation is as close as possible to the
197-
# global coverage. If we interpret the result for the four methods here :
198-
# CV+ seems to be the better one.
199-
# - And with the hsic correlation coefficient, we have the
200-
# same interpretation : :func:`~mapie.metrics.hsic` computes the correlation
201-
# between the coverage indicator and the interval size, a value of 0
202-
# translates an independence between the two.
203192
#
204-
# We would like to highlight here the misinterpretation that can be made
205-
# with these metrics. In fact, here CV+ with the absolute residual score
206-
# calculates constant intervals which, by definition, are not adaptive.
207-
# Therefore, it is very important to check that the intervals widths are well
208-
# spread before drawing conclusions (with a plot of the distribution of
209-
# interval widths or a visualisation of the data for example).
193+
# - SSC (Size Stratified Coverage): This measures the maximum violation
194+
# of coverage by grouping intervals by width and computing coverage for
195+
# each group. An adaptive method has a maximum violation close to the global
196+
# coverage. Among the four methods, CV+ performs the best.
210197
#
211-
# In this example, with the hsic correlation coefficient, none of the methods
212-
# stand out from the others. However, the SSC score for the method using the
213-
# gamma score is significantly worse than for CQR and ResidualNormalisedScore,
214-
# even though their global coverage is similar. ResidualNormalisedScore and CQR
215-
# are very close here, with ResidualNormalisedScore being slightly more
216-
# conservative.
198+
# HSIC (Hilbert-Schmidt Independence Criterion): This computes the
199+
# correlation between coverage and interval size. A value of 0 indicates
200+
# independence between the two.
201+
#
202+
# It's important to note that CV+ with the absolute residual score
203+
# calculates constant intervals, which are not adaptive. Therefore,
204+
# checking the distribution of interval widths is crucial before drawing conclusions.
205+
#
206+
# In this example, none of the methods stand out with the HSIC correlation coefficient.
207+
# However, the SSC score for the gamma score method is significantly worse than
208+
# for CQR and ResidualNormalisedScore, despite similar global coverage.
209+
# ResidualNormalisedScore and CQR are very close, with ResidualNormalisedScore
210+
# being slightly more conservative.
217211

218212

219213
# Visualition of the data and predictions
@@ -336,21 +330,19 @@ def plot_coverage_by_width(y, intervals, num_bins, alpha, title="", ax=None):
336330
plt.show()
337331

338332
##############################################################################
339-
# With toy datasets like this, it is easy to compare visually the methods
340-
# with a plot of the data and predictions.
341-
# As mentionned above, a histogram of the ditribution of the interval widths is
342-
# important to accompany the metrics. It is clear from this histogram
343-
# that CV+ is not adaptive, the metrics presented here should not be used
344-
# to evaluate its adaptivity. A wider spread of intervals indicates a more
345-
# adaptive method.
346-
# Finally, with the plot of coverage by bins of intervals grouped by widths
347-
# (which is the output of :func:`~mapie.metrics.regression_ssc`), we want
348-
# the bins to be as constant as possible around the global coverage (here 0.9).
349-
350-
# As the previous metrics show, gamma score does not perform well in terms of
351-
# size stratified coverage. It either over-covers or under-covers too much.
352-
# For ResidualNormalisedScore and CQR, while the first one has several bins
353-
# with over-coverage, the second one has more under-coverage. These results
354-
# are confirmed by the visualisation of the data: CQR is better when the data
355-
# are more spread out, whereas ResidualNormalisedScore is better with small
356-
# intervals.
333+
# With toy datasets, it's easy to visually compare methods using data and
334+
# prediction plots. A histogram of interval widths is crucial to accompany
335+
# the metrics. This histogram shows that CV+ is not adaptive, so the metrics
336+
# should not be used to evaluate its adaptivity. A wider spread of intervals
337+
# indicates a more adaptive method.
338+
#
339+
# The plot of coverage by bins of intervals grouped by widths
340+
# (output of :func:`~mapie.metrics.regression_ssc`) should
341+
# show bins as constant as possible around the global coverage (0.9).
342+
343+
# The gamma score does not perform well in size stratified coverage,
344+
# often over-covering or under-covering. ResidualNormalisedScore has
345+
# several bins with over-coverage, while CQR has more under-coverage.
346+
# Visualizing the data confirms these results: CQR performs better
347+
# with spread-out data, whereas ResidualNormalisedScore is better
348+
# with small intervals.

examples/regression/2-advanced-analysis/plot_conformal_predictive_distribution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def get_cumulative_distribution_function(self, X):
8484

8585
##############################################################################
8686
# Now, we propose to use it with two different conformity scores -
87-
# :class:`~mapie.conformity_score.AbsoluteConformityScore` and
88-
# :class:`~mapie.conformity_score.ResidualNormalisedScore` - in split-conformal
89-
# inference.
87+
# :class:`~mapie.conformity_scores.AbsoluteConformityScore` and
88+
# :class:`~mapie.conformity_scores.ResidualNormalisedScore` -
89+
# in split-conformal inference.
9090

9191
mapie_regressor_1 = MapieConformalPredictiveDistribution(
9292
estimator=LinearRegression(),

examples/regression/2-advanced-analysis/plot_coverage_validity.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def cumulative_average(arr):
172172

173173

174174
##############################################################################
175-
# Experiment 1: Coverage Validity for given confidence_level (confidence level) and
176-
# n_conformalize (data points dedicated to conformalization)
175+
# Experiment 1: Coverage Validity for given confidence_level and n_conformalize
177176
# --------------------------------------------------------------------------------
178177
#
179178
# To begin, we propose to use ``confidence_level=0.8`` and

examples/regression/2-advanced-analysis/plot_cqr_symmetry_difference.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
77
An example plot of :class:`~mapie_v1.regression.ConformalizedQuantileRegressor`
8-
illustrating the impact of the symmetry parameter.
8+
illustrating the impact of the ``symmetric_correction`` parameter.
99
"""
1010
import numpy as np
1111
from matplotlib import pyplot as plt
@@ -124,9 +124,9 @@
124124
plt.show()
125125

126126
##############################################################################
127-
# The symmetric intervals (`symmetry=True`) use a combined set of residuals
128-
# for both bounds, while the asymmetric intervals use distinct residuals for
129-
# each bound, allowing for more flexible and accurate intervals that reflect
130-
# the heteroscedastic nature of the data. The resulting effective coverages
131-
# demonstrate the theoretical guarantee of the target coverage level
132-
# ``confidence_level``.
127+
# The symmetric intervals (``symmetric_correction=True``) use a combined set of residuals
128+
# for both bounds, while the asymmetric intervals (``symmetric_correction=False``)
129+
# use distinct residuals for each bound, allowing for more flexible and
130+
# accurate intervals that reflect the heteroscedastic nature of the data.
131+
# The resulting effective coverages demonstrate the theoretical guarantee of
132+
# the target coverage level ``confidence_level``.

examples/regression/2-advanced-analysis/plot_main-tutorial-regression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
r"""
2-
==============================================================
3-
Tutorial for tabular regression
4-
==============================================================
2+
=======================================================================
3+
Comparison between conformalized quantile regressor and cross methods
4+
=======================================================================
55
66
77
In this tutorial, we compare the prediction intervals estimated by MAPIE on a

examples/regression/2-advanced-analysis/plot_nested-cv.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,30 @@
44
==========================================================================================
55
66
7-
This example compares non-nested and nested cross-validation strategies for
8-
estimating prediction intervals with
7+
This example compares non-nested and nested cross-validation strategies
8+
when using
99
:class:`~mapie_v1.regression.CrossConformalRegressor`.
1010
11-
In the regular sequential method, a cross-validation parameter search is
12-
carried out over the entire training set.
13-
The model with the set of parameters that gives the best score is then used in
14-
MAPIE to estimate the prediction intervals associated with the predictions.
15-
A limitation of this method is that residuals used by MAPIE are computed on
16-
the validation dataset, which can be subject to overfitting as far as
17-
hyperparameter tuning is concerned.
11+
In the regular sequential method, a cross-validation parameter search is performed
12+
on the entire training set. The best model is then used in MAPIE to estimate
13+
prediction intervals. However, as MAPIE computes residuals on
14+
the validation dataset used during hyperparameter tuning, it can lead to
15+
overfitting. This fools MAPIE into being slightly too optimistic with confidence
16+
intervals.
1817
19-
This fools MAPIE into being slightly too optimistic with confidence intervals.
2018
To solve this problem, an alternative option is to perform a nested
2119
cross-validation parameter search directly within the MAPIE estimator on each
2220
*out-of-fold* dataset.
23-
For each testing fold used by MAPIE to store residuals, an internal
24-
cross-validation occurs on the training fold, optimizing hyperparameters.
2521
This ensures that residuals seen by MAPIE are never seen by the algorithm
2622
beforehand. However, this method is much heavier computationally since
2723
it results in ``N * P`` calculations, where *N* is the number of
2824
*out-of-fold* models and *P* the number of parameter search cross-validations,
2925
versus ``N + P`` for the non-nested approach.
3026
31-
Here, we compare the two strategies on a toy dataset. We use the Random
32-
Forest Regressor as a base regressor for the CV+ strategy. For the sake of
33-
light computation, we adopt a RandomizedSearchCV parameter search strategy
34-
with a low number of iterations and with a reproducible random state.
27+
Here, we compare the two strategies on a toy dataset.
3528
3629
The two approaches give slightly different predictions with the nested CV
37-
approach estimating slightly larger prediction interval widths by a
38-
few percents at most (apart from a handful of exceptions).
30+
approach estimating larger prediction interval in average.
3931
4032
For this example, the two approaches result in identical scores and identical
4133
effective coverages.

examples/regression/2-advanced-analysis/plot_timeseries_enbpi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
==================================================================
3-
Estimating prediction intervals of time series forecast with EnbPI
3+
Time series: example of the EnbPI technique
44
==================================================================
55
66
This example uses

0 commit comments

Comments
 (0)