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

Docs #33

Merged
merged 10 commits into from
Dec 1, 2022
Merged

Docs #33

merged 10 commits into from
Dec 1, 2022

Conversation

pat-alt
Copy link
Member

@pat-alt pat-alt commented Nov 30, 2022

Some early work on regression docs (-> blog post). In regions of the domain that were not seen during training, predictive uncertainty should be really high (no?). See, for example, my results for a Bayesian Neural Network lifted from LaplaceRedux.jl:

image

When I run a similar experiment using CP (here split conformal for XGBoost), results look very different:

image

Considering how CP works, I don’t find this result too surprising, it’s just not great and I’m now a bit confused as to how exactly the coverage guarantees work.

The chart is produced in this notebook, where I’ve been trying to replicate this tutorial from MAPIE.

It would be useful to cross-check the results against the MAPIE results (notebook stored here). In there they don't really look at values of x outside of the training range at the prediction stage, but it should be straight-forward to make adjustments to the code in the notebook. (EDIT: done below)

@pat-alt pat-alt added the documentation Improvements or additions to documentation label Nov 30, 2022
@pat-alt pat-alt assigned pat-alt and unassigned pat-alt Nov 30, 2022
@pat-alt
Copy link
Member Author

pat-alt commented Nov 30, 2022

I've now run the MAPIE tutorial with gradient boosting instead of polynomial reg and the results are the same (so this is not an implementation issue):

image

Quite puzzled now: looking at the chart, test coverage left and right of the training points is very low. I guess we don't have exchangeability in this case or I'm just misunderstanding the marginal coverage property. @aangelopoulos @valeman perhaps you can enlighten me? Sorry if trivial, I have serious brain fog right now.

@codecov-commenter
Copy link

codecov-commenter commented Dec 1, 2022

Codecov Report

Merging #33 (0ad8296) into main (479b94f) will decrease coverage by 12.86%.
The diff coverage is 46.23%.

@@             Coverage Diff             @@
##             main      #33       +/-   ##
===========================================
- Coverage   99.32%   86.45%   -12.87%     
===========================================
  Files           6        9        +3     
  Lines         297      384       +87     
===========================================
+ Hits          295      332       +37     
- Misses          2       52       +50     
Impacted Files Coverage Δ
src/ConformalModels/inductive_bayes.jl 0.00% <0.00%> (ø)
src/ConformalModels/plotting.jl 50.00% <50.00%> (ø)
src/ConformalModels/inductive_classification.jl 98.41% <100.00%> (ø)
src/ConformalModels/inductive_regression.jl 100.00% <100.00%> (ø)
src/ConformalModels/transductive_classification.jl 100.00% <100.00%> (ø)
src/ConformalModels/transductive_regression.jl 100.00% <100.00%> (ø)
src/ConformalModels/utils.jl 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pat-alt
Copy link
Member Author

pat-alt commented Dec 1, 2022

When using polynomial regression as opposed to gradient boosting, the results look better (in some cases). But this is driven by the fact that separate fits for subsets of the data (CV, Jackknife, ...) reflect the underlying stochasticity of the data.

image

Again, I suppose exchangeability is violated: I draw training data from $\mathcal{X}\sim\text{Unif}(-3,3)$ and then map to $\mathcal{Y}$. Test data left and right of the training data is not drawn from $\mathcal{X}$, so we have covariate shift (will be interesting to look at Section 4.5 in this context). Is that right @aangelopoulos? Thanks in advance and apologies if trivial (still fairly new territory for me and trying to wrap my head around things).

Edit: Also Section 3 of the MAPIE tutorial seems to be looking at pretty much the same thing.

@pat-alt pat-alt merged commit 7a95def into main Dec 1, 2022
@aangelopoulos
Copy link

Hey @pat-alt ! Happy to help!

I think you have the right idea --- the example that you've given comes from an extreme covariate shift.
If you run covariate shift conformal using Section 4.5 of the gentle intro, what will happen is that your intervals will explode outside the training data, since the likelihood ratio gets very large.

Without using the covariate shift technique, conformal will only give you the marginal guarantee if the new data is i.i.d. with your old data... so the regions with no training data don't really matter, since they occur with very low probability.

My suggestion would be this. If you like the way the Bayesian NN performs in this setting, use it as your heuristic notion of uncertainty. Then calibrate it with conformal. Best of both worlds!

@pat-alt
Copy link
Member Author

pat-alt commented Dec 2, 2022

Hey @pat-alt ! Happy to help!

I think you have the right idea --- the example that you've given comes from an extreme covariate shift. If you run covariate shift conformal using Section 4.5 of the gentle intro, what will happen is that your intervals will explode outside the training data, since the likelihood ratio gets very large.

Without using the covariate shift technique, conformal will only give you the marginal guarantee if the new data is i.i.d. with your old data... so the regions with no training data don't really matter, since they occur with very low probability.

My suggestion would be this. If you like the way the Bayesian NN performs in this setting, use it as your heuristic notion of uncertainty. Then calibrate it with conformal. Best of both worlds!

Got it - thank you very much!

I'm gradually working my way through your tutorial (which is fantastic by the way!). Both Conformalized Bayes #31 and covariate shift conformal #39 are on the to-do list 😄

Thanks again for your help - much appreciated!

@aangelopoulos
Copy link

Thanks Pat!! This package that you are building is great!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants