hi,I have a question about the prediction,pls check the following code and the comments
#data
x_train,x_test=np.random.random((100,5)),np.random.random((30,5))
y_train,y_test=np.random.random((100,1)),np.random.random((30,1))
#train
with pm.Model() as model:
a = pm.Normal("a", 0.0, 0.5)
b = pm.Normal("b", 0.0, 1.0,shape=(5,1))
mu = a + pm.math.dot(pm.MutableData("x",x_train),b)
sigma = pm.Exponential("sigma", 1.0)
#case1: here the prediction target is mu, which makes sense
pm.Normal("obs", mu=pm.Deterministic("y",mu), sigma=sigma, observed=y_train)
#case2: but I saw some cases is as the following
#pm.Normal("obs", mu=mu, sigma=sigma, observed=pm.MutableData("y",y_train))
trace = pm.sample()
#predict
#for case1,it works,for case2,raise the error “shape mismatch”
with model:
pm.set_data({"x": x_test})
# use the updated values and predict outcomes and probabilities:
idata_2 = pm.sample_posterior_predictive(
trace,
var_names=["y"],
return_inferencedata=True,
predictions=True,
#extend_inferencedata=True,
random_seed=100,
)
a=idata_2.predictions["y"].mean(("chain", "draw"))
================
so,my question is where should we set the “y” for prediction target? the mu or the observed?
I am really confused many example show the target is on observed,but I did not see workable code.
and the api consitency is really a big problem,cause so many examples on website can not work!
thanks!