Obtaining predictions from multilevel model trace

To add onto @OriolAbril, to get parameter estimates, you can just take directly from the trace like you do in the second method. Generally, pm.sample_posterior_predictive() is used to get samples from the model’s prediction of observed data. So in this case, you can just use pm.sample_posterior_predictive(partial_pooling_trace)["y"] to get posterior predictions. Then, if you change the data in the shared variables daypart_idx and temperature, you can get predictions on new/unseen/artifical data. This is great for checking the posterior predictions of your model given a wide variety and combination of input values.

1 Like