pymc.set_data#

pymc.set_data(new_data, model=None, *, coords=None)[source]#

Sets the value of one or more data container variables.

Parameters
new_data: dict

New values for the data containers. The keys of the dictionary are the variables’ names in the model and the values are the objects with which to update.

model: Model (optional if in `with` context)

Examples

>>> import pymc as pm
>>> with pm.Model() as model:
...     x = pm.MutableData('x', [1., 2., 3.])
...     y = pm.MutableData('y', [1., 2., 3.])
...     beta = pm.Normal('beta', 0, 1)
...     obs = pm.Normal('obs', x * beta, 1, observed=y)
...     idata = pm.sample(1000, tune=1000)

Set the value of x to predict on new data.

>>> with model:
...     pm.set_data({'x': [5., 6., 9.]})
...     y_test = pm.sample_posterior_predictive(idata)
>>> y_test['obs'].mean(axis=0)
array([4.6088569 , 5.54128318, 8.32953844])