-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Allow plot_cap()
to show predictions at the observation level
#668
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
Thanks a lot for the nice PR! I added some suggestions for changes. Let me know if you have any questions :)
@GStechschulte I just updated the PR with the mtcars dataset, now you can do |
Codecov Report
@@ Coverage Diff @@
## main #668 +/- ##
==========================================
+ Coverage 87.62% 87.80% +0.18%
==========================================
Files 40 40
Lines 2650 2665 +15
==========================================
+ Hits 2322 2340 +18
+ Misses 328 325 -3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Great, thanks! I am going to perform a few more examples (other than the mtcars dataset and model) first, and then you can review the example(s). I plan to be finished with this (and move from a draft PR to PR) by the end of this weekend 23.04. As far as adding tests in the |
Sounds great! Thanks for the extra examples. It's not trivial to test plotting functions. That's why the code in See the test code also uses mtcars, but it's loaded from the tests module. You could remove that and load it with |
Hey @tomicapretto I have been testing this functionality with a variety of different models (linear, negative binomial, binomial, and categorical regression). The examples can be found in this Gist. Most of them look good besides categorical regression (which I opened an issue), and models with binary responses that are represented by the proportion alias. The problem with |
@GStechschulte thanks for the thorough notebook. It's a great piece of work! Here my answers
What do you think? |
* FAQ page first draft * Update docs/faq.rst Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com> * Update docs/faq.rst Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com> * Remove general bayesian modelling questions + minor fixes * Update faq.rst * Update faq.rst --------- Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com>
@tomicapretto Thanks, and indeed, you are correct regarding the scales of the binary responses. Agreed, a bar plot would be a better way to visualize the observations. For this PR, I left this particular example as is. Same for categorical regression; we can collaborate on this issue in #669 One last point regarding adding tests. I suppose one could just copy and paste, albeit with |
@GStechschulte Yes, you can do something like this: @pytest.mark.parametrize("pps", [False, True])
def test_basic(mtcars, pps):
model, idata = mtcars
# Using dictionary
# Horizontal variable is numeric
plot_cap(model, idata, {"horizontal": "hp"}, pps=pps)
# Horizontal variable is categorical
plot_cap(model, idata, {"horizontal": "gear"}, pps=pps)
# Using list
plot_cap(model, idata, ["hp"], pps=pps)
plot_cap(model, idata, ["gear"], pps=pps) Havent' tested locally but I think that's it. Let me know if you need help :) |
@GStechschulte looks like it can be merged? :D |
Indeed, it can be merged :) thanks for your code reviews and quick feedback! |
…inos#668) * plot_cap using post. pred. samples * add mtcars dataset and test plot_cap using post. pred. samples * plot_cap show predictions at obs. level * remove unused code and formatting * Add mtcars as a dataset. Bump PyMC to 5.3.0 * FAQ page first draft (bambinos#657) * FAQ page first draft * Update docs/faq.rst Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com> * Update docs/faq.rst Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com> * Remove general bayesian modelling questions + minor fixes * Update faq.rst * Update faq.rst --------- Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com> * black reformatting * add tests for pps=bool using pytest parameterization --------- Co-authored-by: Tomas Capretto <tomicapretto@gmail.com> Co-authored-by: Abuzar Mahmood <abuzarmahmood@gmail.com> Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com>
This draft PR addresses issue #623 to allow
plot_cap()
to show predictions at the observation level, i.e., to use the adjusted posterior predictive distribution.This is achieved by adding an additional boolean argument
pps
(posterior predictive sample) to theplot_cap()
function. If true, then the adjusted posterior predictive distribution is plotted for the response variable by usingmodel.predict(..., kind="pps")
, else the adjusted posterior is used for plotting, i.e.,model.predict(..., kind="mean")
.Below are some examples:
This is a work in progress and I still need to test on other examples, add tests, and perform linting. However, if anyone has any initial comments or criticisms, let me know. Thanks!