Open Rabeez opened 3 years ago
I'm still experiencing trouble after that change @Rabeez the error message changed though:
ValueError: Cannot broadcast provided shapes (0,), (), () given size: ()
Code from the previous cell with the change as recommended above
d = d.loc[d.age > 17,]
d['age'] = ( d['age'] - 18 ) / ( 65 - 18 )
d['married'] = d['married'].astype('int')
Model 6.9 cell code:
#married = theano.shared(d.married)
with pm.Model() as model_69:
# Data
age = pm.Data('age', d['age'].values)
married = pm.Data('married', d['married'].values)
happiness = pm.Data('happiness', d['happiness'].values)
# Priors
a = pm.Normal('a', mu=0, sd=1, shape=2)
bA = pm.Normal('bA', mu=0, sd=2)
sigma = pm.Exponential('sigma', lam=1)
# Regression
mu = a[married] + bA * age
happy_hat = pm.Normal('happy_hat', mu=mu, sd=sigma, observed=happiness)
# Prior sampling, trace definition and posterior sampling
prior = pm.sample_prior_predictive(samples = 30)
posterior_69 = pm.sample()
posterior_pred_69 = pm.sample_posterior_predictive(posterior_69)
Running pymc3 3.10, tried reverting back to 3.7 for the purposes of working my way through this textbook, but I was running into tons of issues with theano. Any advice?
EDIT: It appears that this may be a result of an interaction with age though as the very first line of the stack mentions this: WARNING (theano.tensor.opt): Cannot construct a scalar test value from a test value with no size: age
I was getting a
TypeError
on this line even though you had casted the column to anInt64
already.https://github.com/gbosquechacon/statrethink_course_in_pymc3/blob/820436d718b4d6b0b7bf5c54e8bd51a12a3dbd28/notebooks/pymc3/rethink_stats_pymc3_w04.ipynb#L430
For some reason casting to
Int64
does not make a numpy typed series and causes Theano to freak out. Just changing this cast toastype('int')
here solves the issue.https://github.com/gbosquechacon/statrethink_course_in_pymc3/blob/820436d718b4d6b0b7bf5c54e8bd51a12a3dbd28/notebooks/pymc3/rethink_stats_pymc3_w04.ipynb#L396
I'll submit a PR later unless you get to this first 😄