New pymc3 user here
I’ve been trying to get a slightly modified version of this pymc3 GLM logistic regression tutorial to work - to no avail.
print(pm.__version__)
3.6
I want to use custom (non-default) priors for the GLM coefficients. Here’s my code:
with pm.Model() as logistic_model:
# define somewhat better priors
n_coeffs = 4
my_priors = {"Regressor": pm.distributions.Normal('dummy', mu=0, tau=1e-2, shape=(n_coeffs,))}
pm.glm.GLM.from_formula('income ~ age + age2 + educ + hours', data, family=pm.glm.families.Binomial(), priors=my_priors)
trace_logistic_model = pm.sample(2000, chains=1, tune=1000)
The data
are coming from a Pandas DataFrame
with column names age
, age2
etc.
I keep getting the following error, what gives?
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-23-471a1af6a7b1> in <module>()
5 my_priors = {"Regressor": pm.distributions.Normal('dummy', mu=0, tau=1e-2, shape=(n_coeffs,))}
6
----> 7 pm.glm.GLM.from_formula('income ~ age + age2 + educ + hours', data, family=pm.glm.families.Binomial(), priors=my_priors)
8
9 trace_logistic_model = pm.sample(2000, chains=1, tune=1000)
/usr/local/lib/python3.6/dist-packages/pymc3/glm/linear.py in from_formula(cls, formula, data, priors, vars, family, name, model, offset)
147 return cls(np.asarray(x), np.asarray(y)[:, -1], intercept=False,
148 labels=labels, priors=priors, vars=vars, family=family,
--> 149 name=name, model=model, offset=offset)
150
151
/usr/local/lib/python3.6/dist-packages/pymc3/model.py in __call__(cls, *args, **kwargs)
282 instance = cls.__new__(cls, *args, **kwargs)
283 with instance: # appends context
--> 284 instance.__init__(*args, **kwargs)
285 return instance
286
/usr/local/lib/python3.6/dist-packages/pymc3/glm/linear.py in __init__(self, x, y, intercept, labels, priors, vars, family, name, model, offset)
122 x, y, intercept=intercept, labels=labels,
123 priors=priors, vars=vars, name=name,
--> 124 model=model, offset=offset
125 )
126
/usr/local/lib/python3.6/dist-packages/pymc3/glm/linear.py in __init__(self, x, y, intercept, labels, priors, vars, name, model, offset)
75 priors.get(
76 'Regressor',
---> 77 self.default_regressor_prior
78 )
79 )
/usr/local/lib/python3.6/dist-packages/pymc3/model.py in Var(self, name, dist, data, total_size)
807 with self:
808 var = FreeRV(name=name, distribution=dist,
--> 809 total_size=total_size, model=self)
810 self.free_RVs.append(var)
811 else:
/usr/local/lib/python3.6/dist-packages/pymc3/model.py in __init__(self, type, owner, index, name, distribution, total_size, model)
1203 if distribution is not None:
1204 self.dshape = tuple(distribution.shape)
-> 1205 self.dsize = int(np.prod(distribution.shape))
1206 self.distribution = distribution
1207 self.tag.test_value = np.ones(
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in prod(a, axis, dtype, out, keepdims)
2561 pass
2562 else:
-> 2563 return prod(axis=axis, dtype=dtype, out=out, **kwargs)
2564
2565 return _methods._prod(a, axis=axis, dtype=dtype,
TypeError: prod() got an unexpected keyword argument 'out'