I’m quite new to PyMC and admitteldy much more comfortable in R and Stan than Py so I’m probably doing something rudimentary wrong and I’m not tracking all the variations between different versions of PyMC. I have a very simple model that I’ve been toying with to learn that I’ve copied from here. I had started with more complex modeling but realized that I was in way over my head.
Anyhow, here is my attempt to get some predictions:
# Predictions - generate new data
new_data = np.random.randn(3, 3)
#concat my existing features with new ones?
tmp = np.concatenate((features, new_data))
# should coords have 3 or 103? Neither seems to work confusingly.
new_coords = {
# dim 1: len of df
'obs_id': np.arange(0,3), #is this all coords from concat'd set or just for new?
# dim 2: feature cats.
'features': ['treatment', 'cov1', 'cov2']
}
with hierarchical_model:
# set it over the feature data? Is this needed? doesn’t work anyways.
hierarchical_model.set_data(name = "feature_data", values = tmp, coords=new_coords)
# generate preds, seems to work
predictions = pm.sample_posterior_predictive(hierarchical_trace, predictions=True)
# this doesn’t exist any more, not sure how to replace it?
preds = az.from_pymc3_predictions(predictions,
coords=new_coords,
idata_orig=lm_idata,
inplace=False)
# # get y-hat for new X data
preds.predictions['y'].median(dim=('chain', 'draw')).values
# # view y-hat as 94% HDI
az.plot_posterior(preds, group="predictions");
I’m guessing that there’s some trickery with how we set the co-ordinates that I can’t seem to puzzle out from the docs and sadly much of the code that I can find to reference no longer seems to work. Any advice much apprecated!