After obtaining a trace from my model, I can change the Theano predictors to generate out-of-sample predictions, as described in the docs:
https://docs.pymc.io/notebooks/posterior_predictive.html
# Changing values here will also change values in the model
predictors_shared.set_value(predictors_out_of_sample)
# Simply running PPC will use the updated values and do prediction
ppc = pm.sample_ppc(trace, model=model, samples=100)
I want to save my model today and use it for out-of-sample predictions next week. How can I achieve this?
Hereās what Iāve tried:
- Pickle model and trace so I can load them later, as described here: https://stackoverflow.com/a/44768217
- Update predictors in loaded model - how? Theano set_value() method doesnāt make sense from a loaded model and trace. I tried making a 2nd copy of my model using out-of-sample predictors as input.
- Run sample_ppc() with out-of-sample predictors. I tried running sample_ppc() on my 2nd model with out-of-sample predictors using the trace from my previously trained model. The two models are specified exactly the same but with different predictor samples. This fails due to broadcasting different sample lengths.
This seems like a common use case for anyone doing predictive modeling. How can I make out-of-sample predictions from a model and trace that I saved previously? Itās very inefficient to retrain my model from scratch every time I want to make out of sample predictions.