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

[ENHANCEMENT] Covariate shift conformal #72

Open
gmartinonQM opened this issue Jul 9, 2021 · 12 comments · May be fixed by #151
Open

[ENHANCEMENT] Covariate shift conformal #72

gmartinonQM opened this issue Jul 9, 2021 · 12 comments · May be fixed by #151
Labels
Discussion in progress Discussion ongoing between the Mapie team and the author. Enhancement Type: enhancement (new feature or request) Other or internal If no other grey tag is relevant or if issue from the MAPIE team Source: developers Proposed by developers.

Comments

@gmartinonQM
Copy link
Collaborator

As described in this paper :
https://arxiv.org/abs/1904.06019

@gmartinonQM gmartinonQM added the Enhancement Type: enhancement (new feature or request) label Jul 9, 2021
@RudrakshTuwani
Copy link

Hi, I recently implemented this paper as part of a project and would love to discuss how it could be added to MAPIE.

@gmartinonQM
Copy link
Collaborator Author

Hi @RudrakshTuwani , thanks for your interest in MAPIE ! Maybe the cleanest way to do this would be to

  1. share a github repo with your implementation so that we can give you feedbacks
  2. init a pull request on MAPIE, making a separate class of your own in a dedicated module, following the template provided by the regression module
  3. Don't forget to write unit tests so as to maintain 100% coverage and to write a pedagogical example

@RudrakshTuwani
Copy link

Awesome, thanks for the guidance. I will keep you posted!

@gmartinonQM
Copy link
Collaborator Author

Any news about this @RudrakshTuwani ?

@RudrakshTuwani
Copy link

Hey @gmartinonQM, I had implemented the density ratio estimation class and a basic API for weighted conformal before life got in the way. Is it possible for us to meet virtually next week? I have some high-level questions and I feel like we can progress faster that way.

@RudrakshTuwani
Copy link

RudrakshTuwani commented Mar 29, 2022

Hello @gmartinonQM, I have some good news! I have implemented the split conformal variant in my fork here: https://github.com/RudrakshTuwani/MAPIE?organization=RudrakshTuwani&organization=RudrakshTuwani

Changes in files:

  1. mapie/regression.py - Added class MapieCovShiftRegressor.
  2. mapie/dre.py - Added classes DensityRatioEstimator and ProbClassificationDRE.
  3. mapie/utils.py - Added a function empirical_quantile for calculating weighted empirical quantile.

The replication of paper results is at examples/regression/4-covariate-shift/paper_replication.ipynb. There are a couple of differences but they are mostly due to different model defaults between Python and R. In general, we see that MapieCovShiftRegressor is able to adapt to covariate shift with oracle as well as estimated density ratios.

There's still work to be done. Right now I have just limited the functionality of MapieCovShiftRegressor to cv="prefit" and method="base". I can try working on adapting the class to other scenarios. It will likely be non-trivial due to density ratio estimation and I think I would need to spend some time thinking about how to do it in a way that doesn't violate exchangeability. If you feel the current limitations are not significant, I can also spend time on writing tests and documentation.

Let me know what you think! Thank you :)

@gmartinonQM
Copy link
Collaborator Author

Hi @RudrakshTuwani , thanks for your contribution ! Could you create a pull request of your fork toward master ?

@RudrakshTuwani RudrakshTuwani linked a pull request Mar 30, 2022 that will close this issue
7 tasks
@nilslacroix
Copy link

Tested this out of curiosity. Does not work anymore unfortunately, I think some fitting parameters have to be added to the model since it checks for residuals_

@vtaquet
Copy link
Member

vtaquet commented Jul 11, 2022

Hi @RudrakshTuwani, thanks again for your great work and sorry about our silence over the past few weeks.

You may have noticed that we implemented a new type of class ConformityScore that allows the user to define "custom" conformity scores (instead of residuals). Following this update, I adapted your implementation of the covariate shift method so the method can directly be used in MapieRegressor through a CovariateShiftConformityScore class. I pushed a branch here : https://github.com/scikit-learn-contrib/MAPIE/tree/add-covshift-in-conformityscore. The branch includes the modified files and your notebook adapted to my suggested modifications (I obtain the same results).

Please let me know what you'd like us to do. If you have time in the following weeks, I would be happy to help you finishing the pull request you started by considering the suggested modifications (and adding some unit tests to make sure everything is tested and controlled). If you don't have time, I can also keep working on your PR and add you as a reviewer.

Thank you once again !

@RudrakshTuwani
Copy link

Hey @vtaquet , thanks for getting back to me and no worries! Yes, I would love to finish the pull request and make a contribution to MAPIE. :)

I can take a look at finishing up the tasks this weekend. Thanks!

@RudrakshTuwani
Copy link

Hey, I apologize for the radio silence on this!
What's the cleanest way to do this? Should I just clone @vtaquet's branch and add a few tests? Thanks!

@vtaquet
Copy link
Member

vtaquet commented Aug 22, 2022

Hi @RudrakshTuwani ! Yes, you can clone my branch, double-check it and add the unit tests to keep the 100% test coverage. Please let me know if you have some questions about it. Thanks again !

@thibaultcordier thibaultcordier added the Source: developers Proposed by developers. label Jul 4, 2023
@Valentin-Laurent Valentin-Laurent added Discussion in progress Discussion ongoing between the Mapie team and the author. Other or internal If no other grey tag is relevant or if issue from the MAPIE team labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion in progress Discussion ongoing between the Mapie team and the author. Enhancement Type: enhancement (new feature or request) Other or internal If no other grey tag is relevant or if issue from the MAPIE team Source: developers Proposed by developers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants