I am learning Bayesian inference by the book Bayesian Analysis with Python. However, when using plot_ppc, I got AttributeError and the warning
/usr/local/Caskroom/miniconda/base/envs/kaggle/lib/python3.9/site-packages/pymc3/sampling.py:1689: UserWarning: samples parameter is smaller than nchains times ndraws, some draws and/or chains may not be represented in the returned posterior predictive sample warnings.warn(
The model is
shift = pd.read_csv('../data/chemical_shifts.csv')
with pm.Model() as model_g:
μ = pm.Uniform('μ', lower=40, upper=70)
σ = pm.HalfNormal('σ', sd=10)
y = pm.Normal('y', mu=μ, sd=σ, observed=shift)
trace_g = pm.sample(1000, return_inferencedata=True)
If I used the following codes
with model_g:
y_pred_g = pm.sample_posterior_predictive(trace_g, 100, random_seed=123)
data_ppc = az.from_pymc3(trace_g.posterior, posterior_predictive=y_pred_g) # 'Dataset' object has no attribute 'report'
I got 'Dataset' object has no attribute 'report'.
If I used the following codes
with model_g:
y_pred_g = pm.sample_posterior_predictive(trace_g, 100, random_seed=123)
data_ppc = az.from_pymc3(trace_g, posterior_predictive=y_pred_g) # AttributeError: 'InferenceData' object has no attribute 'report'
I got AttributeError: 'InferenceData' object has no attribute 'report'.
ArviZ version: 0.11.2 PyMC3 Version: 3.11.2 Aesara/Theano Version: 1.1.2 Python Version: 3.9.6 Operating system: MacOS Big Sur How did you install PyMC3: conda
You are passing
return_inferancedata=Truetopm.sample(), which according to the PyMC3 documentation will return anInferenceDataobject rather than aMultiTraceobject.The
from_pymc3function, however, expects aMultiTraceobject.The good news is that
from_pymc3returns anInferenceDataobject, so you can solve this in one of two ways:from_pymc3calls, since it returnsInferenceData, which you already have due toreturn_inferencedata=True.return_inferencedata=False(you can also remove that argument, but the documentation states that in the future it will default toTrue, so to be future proof it's best to explicitly set it toFalse). This will return aMultiTracewhich can be passed tofrom_pymc3.