Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Adaptive Conformal Inference method for Time Series #341

Merged

Conversation

thibaultcordier
Copy link
Collaborator

@thibaultcordier thibaultcordier commented Aug 11, 2023

Description

Adaptive Conformal Inference for time series with general dependency.

  • Gibbs, I., & Candes, E. (2021). Adaptive conformal inference under distribution shift. Advances in Neural Information Processing Systems, 34, 1660-1672.
  • Zaffran, M., Féron, O., Goude, Y., Josse, J., & Dieuleveut, A. (2022, June). Adaptive conformal predictions for time series. In International Conference on Machine Learning (pp. 25834-25866). PMLR.

Fixes #334
Fixes #390

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Test that ACI method works.
  • Test that infinite prediction intervals can be produced in regressor classes.

Checklist

  • I have read the contributing guidelines
  • I have updated the HISTORY.rst and AUTHORS.rst files
  • Linting passes successfully : make lint
  • Typing passes successfully : make type-check
  • Unit tests pass successfully : make tests
  • Coverage is 100% : make coverage
  • Documentation builds successfully : make doc

Copy link
Collaborator Author

@thibaultcordier thibaultcordier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QMaphan, I offer you a quick first review for your contribution for scores applied to regression. All suggestions will improve the style and visibility of the code.

I'd also suggest adapting your score so that it's called with the following signature: (y_true, y_interval) instead of (y_true, y_low, y_up) .

mapie/metrics.py Outdated Show resolved Hide resolved
HISTORY.rst Outdated Show resolved Hide resolved
HISTORY.rst Outdated Show resolved Hide resolved
mapie/metrics.py Outdated Show resolved Hide resolved
mapie/metrics.py Outdated Show resolved Hide resolved
mapie/tests/test_metrics.py Outdated Show resolved Hide resolved
mapie/tests/test_metrics.py Outdated Show resolved Hide resolved
mapie/tests/test_metrics.py Outdated Show resolved Hide resolved
mapie/tests/test_metrics.py Outdated Show resolved Hide resolved
mapie/regression/time_series_regression.py Show resolved Hide resolved
alpha = alpha_np
return alpha

def adapt_conformal_inference(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def adapt_conformal_inference(
def _adapt_conformal_inference(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not, but then we'd have to replace partial_fit with _partial_fit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because it would be a breaking changes (cf my comment about partial_fit)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I prefer to leave it as is.

@@ -96,45 +112,27 @@ def _relative_conformity_scores(
)
return scores

def fit(
def partial_fit(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I well understood your PR, now if method == "enbpi" then you can either call .update or .partial_fit. For now maybe we can keep both, but if we want to keep only the .update we could add a DepreciationWarning to partial_fit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment, I have no intention of withdrawing it.

self,
X: ArrayLike,
y: ArrayLike,
ensemble: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoudnl't we keep the same value of ensemble for all the class ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but we also have the same problem with sym in this case. I'm doing this to reproduce the results.

@@ -633,6 +633,8 @@ def predict(
X: ArrayLike,
ensemble: bool = False,
alpha: Optional[Union[float, Iterable[float]]] = None,
optimize_beta: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@LacombeLouis LacombeLouis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some last small changes but overall this PR will go a long way for MAPIE!

@thibaultcordier thibaultcordier merged commit 941ca35 into master Jan 3, 2024
8 checks passed
@Valentin-Laurent Valentin-Laurent deleted the 334-adaptive-conformal-predictions-for-time-series branch November 12, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants