-
Notifications
You must be signed in to change notification settings - Fork 50
Add CP_MDA-exact algorithm for correct uncertainty estimates with missing data. #231
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
base: main
Are you sure you want to change the base?
Conversation
Introduces the CP_missing_data extension for TabPFNRegressor, providing conformal prediction intervals in the presence of missing data. Includes implementation, example usage, and tests for calibration and prediction with missing data patterns.
Less features to reduce the number of masks for the example
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary of ChangesHello @Fdvanleeuwen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates the CP_MDA-exact algorithm into the tabpfn_extensions library, enabling TabPFNRegressor to generate accurate and calibrated uncertainty estimates even in the presence of missing data. The solution provides a robust framework for handling various missing data patterns by calculating specific correction terms, thereby improving the reliability of predictions for tabular data. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the CP_MDA-exact algorithm for handling missing data with TabPFN, which is a valuable addition. The implementation is well-structured into two classes for training and prediction. I've found a critical issue in the data selection logic that could lead to incorrect calibration, which needs to be addressed. Additionally, I've provided feedback on improving docstrings, code style consistency, and the flexibility of the implementation. The tests are a good start, but one of them could be made more robust. The example script is clear and helpful.
| def run_TABPFN(self): | ||
| """Fit the TabPFN model.""" | ||
| # fit model | ||
| m_fit = TabPFNRegressor() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TabPFNRegressor is instantiated with its default parameters, which limits flexibility. Consider allowing users to pass custom arguments to TabPFNRegressor through the CP_MDA_TabPFNRegressor constructor.
You could modify the __init__ method to accept **tabpfn_kwargs and store them:
def __init__(self, X_train, Y_train, quantiles, val_size, seed, **tabpfn_kwargs):
# ...
self.tabpfn_kwargs = tabpfn_kwargsThen, you can use these arguments when creating the instance here.
| m_fit = TabPFNRegressor() | |
| m_fit = TabPFNRegressor(**getattr(self, 'tabpfn_kwargs', {})) |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Make seed optional and update name change of internal function in pipeline.
bejaeger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Fdvanleeuwen ,
thank you so much for this contribution. It looks great all in all. There are a few stylistic things I commented on that would be great if you could change them. The CI also shows some errors. If you could fix these I can have a closer look at the method.
Thanks again!
| from tabpfn import TabPFNRegressor | ||
| except ImportError: | ||
| # Fall back to TabPFN client | ||
| from tabpfn_client import TabPFNRegressor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use from tabpfn_extensions.utils import TabPFNClassifier, TabPFNRegressor instead :)
| from tabpfn import TabPFNRegressor | ||
| except ImportError: | ||
| # Fall back to TabPFN client | ||
| from tabpfn_client import TabPFNRegressor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: from tabpfn_extensions.utils import TabPFNClassifier, TabPFNRegressor
| Parameters: | ||
| X_train : matrix-like of shape (n_samples, n_predictors) | ||
|
|
||
| Y_train : array-like of continuous outcome with shape (n_samples,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stick to the convention of parsing the data during the fit() call. Only configuration should go here.
| """Split data into training and validation sets.""" | ||
| # create df with missing data indicator | ||
| missing_bool_df = self.X.isnull().astype(int) | ||
| self.X_train, self.X_val, Y_train_arr, Y_val_arr, self.Mask_train, self.Mask_val = train_test_split( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our convention is to use y for the target variable (lowercase).
Please also make Mask_train/val lowercase -> mask_train/val to stick to python conventions
| self.split_data() | ||
| self.run_TABPFN() | ||
| self.mask_preprocess() | ||
| mask_unique, model = self.create_calibration_sets() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easier to follow the code if you return the variables needed in the next steps rather than making them an instance variable. Would be a nice change.
|
|
||
| TabPFN: Fitted TabPFNRegressor model. | ||
|
|
||
| X_new : matrix-like of shape (n_samples, n_predictors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, let's parse X_new that during fit()
| """Convenience method to run the entire pipeline""" | ||
| self.obtain_preds() | ||
| self.match_mask() | ||
| CP_results = self.perform_correction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar here, could we return and parse the arguments needed?
|
|
||
| """ | ||
|
|
||
| def __init__(self, X_train, Y_train, quantiles, val_size, seed=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add type hints here and in all other functions.
The CP_MDA-exact algorithm [1] allows users to obtain conformalised uncertainty estimates for TabPFNRegressor. This allows users to have correct uncertainty estimates based on the missing masks, as described in [2]. There are two functions:
CP_MDA_TabPFNRegressor: for fitting TabPFNRegressor and obtaining the correction terms for each mask.
CP_MDA_TabPFNRegressor_newdata: for applying the fitted model (and correction terms) to new test cases.
[1] Margaux Zaffran, Aymeric Dieuleveut, Julie Josse, and Yaniv Romano. Conformal prediction with missing
values. In International Conference on Machine Learning, pages 40578–40604. PMLR, 2023.
[2] van Leeuwen, F. D. Conformal Prediction for Tabular Prior-Data Fitted Networks with Missing data. In EurIPS 2025 Workshop: AI for Tabular Data.