-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Surprising predict() behaviour #533
Comments
Working with distributions and samples is the bread and butter of computational bayesians. What about adding or extending and example about this. The more examples we have about how to use inferencedata the least steep that learning curve will be. |
I understand your point, and I agree it's harder to think about samples. Even more, we have chains and draws, and new data structures as well which make things more complicated I think. On the other hand, I don't think we should change anything in the I think the way to make Bambi more appealing to newcomers (both beginners and people experienced with frequentist frameworks) is to provide utility functions that do much if not all of the heavy lifting (for example #517). In this particular case, I think there could be another utility function that post-process the InferenceData to return point estimates. This way, users will be aware that Bambi returns a whole posterior (as samples) but they are explicitly converting them to point estimates (no matter they don't implement that conversion by hand). Some open questions
|
Yes I think a utility method is a good solution and would address this quite simply, I think it'd be quite small as my analogous code I use in my pymc models is just: y_test = pm.sample_posterior_predictive(results)
return y_test.posterior_predictive.y.mean(axis=(0,1)).values If it were a brand new library, I'd argue for keeping In terms of where it should exist, ideally it'd be another method on the bambi Model object named something like I'll produce a small example branch with this feature on (as I think it should be fairly straightforward) to better demonstrate what I'm thinking of. |
Here's an example of what I was thinking of. I appreciate it's incredibly simple (literally a one liner once you've called 'predict') but this one-liner took me a few hours to work out the first time I used bambi 😅 |
Notice that with InferenceData/xarray you can use labels. y_test.posterior_predictive["y"].mean(("chain", "draw")) This generally requires writing more characters, but the result is easier to read. For example, here is clear that the intention is to average over both chains and draws. Another comment. We have discussed in ArviZ to hide the information about the chains to the user. The main reason is to simplify working with InferenceData, because as a general rule uses do not care about directly accessing to individuals chains. The chain information is useful mostly to diagnose samples, so ArviZ internally can get access to chains. |
I'm going to close the issue because we're not changing the way |
I'm pretty new to bayesian modelling, but I did find this behaviour to be quite confusing in Bambi. Maybe a good solution would be to have a vignette which went through how to practically work with the XArray objects? |
@gshotwell that's definitely a good idea, thanks! |
I'm not sure if this is an issue as such but more a comment / point of discussion. As a fairly new user to bambi, I found the behaviour of predict() to be very unintuitive because the fit() / predict() interface in the python data science ecosystem has very strong connotions with the standard sklearn interface that's very common.
I've an appreciation of how the bayesian approach is different to the usual ML approach in that generally you're interested in not just making point estimates but getting the full posterior predictive distribution for predictions, however I think it's very beginner friendly to have the option be able to treat the model like the frequentist/ML sklearn-style models for which predict() would produce point estimates. Even if you don't care too much about the full posterior and uncertainty estimation, there's still reasons to prefer the bayesian approach if you're only after point estimates.
One proposal would be to add a "point-estimate-prediction" option alongside "mean" and "pps" which instead returns a numpy array of the per data point predictions. Whilst this would just be equivalent to doing pps then taking the mean, I think this would help the beginner tremendously as otherwise they have to understand the InferenceData/xarray normal structure to be able to do so, which has its own learning curve.
The text was updated successfully, but these errors were encountered: