question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading PPC data into arviz in pymc3

See original GitHub issue

Currently, the easiest way to get data from pymc3 into arviz is via pm.sample(return_inferencedata=True), which gives back an arviz InferenceData object. However, pm.sample_posterior_predictive() only supports dictionary returns.

It’s unclear what the right approach is, as at this point the InferenceData object is already created. I guess we either need an easy, dimension-aware way to add the PPC data later or create a new object with it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kyleabeauchampcommented, Jul 11, 2020

Thanks, the az.concat idea is working, and I’m testing out the PR branch of pymc3 that fixes the keep_size issue. So I think I’m now on track again 😃.

1reaction
OriolAbrilcommented, Jul 7, 2020

To add posterior predictive samples to an inference data object with pymc3, I think the best approach is:

...
    idata = pm.sample(..., return_inference_data=True)
...
    ppc = pm.sample_posterior_predictive(..., keep_size=True)
az.concat(idata, az.from_dict(posterior_predictive=ppc), inplace=True)

There is also issue #1239 to make this last line less convoluted.

As Robert pointed out, to add predictions (out of sample posterior predictive samples) the way to go should be from_pymc3_predictions as this will add the samples returned by sample_posterior_predictive to predictions groups as well as the data used to generate them to constant_data_predictions (assuming you are using pm.Data container).

I commented in the issue you linked as there seems to be a bug with keep_size is a dataset is passed so most of this won’t work for now 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prior and Posterior Predictive Checks — PyMC3 3.11.5 ...
Posterior predictive checks (PPCs) are a great way to validate a model. The idea is to generate data from the model using parameters...
Read more >
Hands On Bayesian Statistics with Python, PyMC3 & ArviZ
Appreciate The Gurus team for scraping the data set. from scipy import stats import arviz as az import numpy as np import matplotlib.pyplot...
Read more >
arviz.plot_ppc: "posterior predictive mean" - Stack Overflow
As you can see both plots show the "posterior predictive mean score", ... Both figures were made using the same data: ... pymc3...
Read more >
Introduction to Computational Statistics with PyMC3
%matplotlib inline import arviz as az import numpy as np import warnings ... of predicted y for each original x in our data...
Read more >
| notebook.community
%matplotlib inline import sklearn import scipy.stats as stats import ... packaging in /usr/local/lib/python3.6/dist-packages (from arviz>=0.4.1->pymc3==3.8) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found