# How can i sample posteriors from training-data, run posterior predictive on testing data (with complex factor graph)

**URL:** <https://discourse.pymc.io/t/how-can-i-sample-posteriors-from-training-data-run-posterior-predictive-on-testing-data-with-complex-factor-graph/11875>\
**Category:** v5\
**Tags:** modeling\
**Created:** [April 12, 2023, 7:46am UTC](https://discourse.pymc.io/t/how-can-i-sample-posteriors-from-training-data-run-posterior-predictive-on-testing-data-with-complex-factor-graph/11875 "2023-04-12T07:46:05Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [April 23, 2023, 11:05am UTC](https://discourse.pymc.io/t/how-can-i-sample-posteriors-from-training-data-run-posterior-predictive-on-testing-data-with-complex-factor-graph/11875/10 "2023-04-23T11:05:37Z")

</div>

I didn’t use arviz. It’s the same as the code i posted here:

> [@Is this half cauchy model correct?](https://discourse.pymc.io/t/is-this-half-cauchy-model-correct/11777/10):
>
> The best practice for out of sample prediction is to: Use pm.MutableData objects to hold your data Include size=X.shape[0] in the likelihood term Use pm.set\_data together with pm.sample\_posterior\_predictive to get out-of-sample predictions. Here is how it looks with your model: with pm.Model() as model: # Here's the mutable data X\_pt = pm.MutableData('X', X\_train) y\_pt = pm.MutableData('y', y\_train) α = pm.Normal("α", mu=0, sigma=1) β = pm.Normal("β", mu=0, sigma=1) …

---

_[View the full topic](https://discourse.pymc.io/t/how-can-i-sample-posteriors-from-training-data-run-posterior-predictive-on-testing-data-with-complex-factor-graph/11875)._
