This is my very first exposure to pymc and I am trying to create a simple linear regression on my dataset.
This is my model:
with pm.Model() as linear_model:
mu = pm.Exponential('mu', lam=0.1)
m = pm.Uniform('m', lower=0, upper=100)
intercept = pm.Normal('intercept', mu=mu, sigma=100)
link = df['size'].values * m + intercept
y = pm.Normal('y', mu=link, sigma=mu, observed=df['price'].values)
with linear_model:
trace = pm.sample(1000, tune=1000)
However, it returns the following error:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [intercept, m, mu]
Sampling 4 chains, 0 divergences: 20%|██ | 1624/8000 [00:06<00:26, 236.68draws/s]
---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/mark/opt/miniconda3/envs/pymc/lib/python3.6/site-packages/pymc3/parallel_sampling.py", line 110, in run
self._start_loop()
File "/Users/mark/opt/miniconda3/envs/pymc/lib/python3.6/site-packages/pymc3/parallel_sampling.py", line 160, in _start_loop
point, stats = self._compute_point()
File "/Users/mark/opt/miniconda3/envs/pymc/lib/python3.6/site-packages/pymc3/parallel_sampling.py", line 191, in _compute_point
point, stats = self._step_method.step(self._point)
File "/Users/mark/opt/miniconda3/envs/pymc/lib/python3.6/site-packages/pymc3/step_methods/arraystep.py", line 247, in step
apoint, stats = self.astep(array)
File "/Users/mark/opt/miniconda3/envs/pymc/lib/python3.6/site-packages/pymc3/step_methods/hmc/base_hmc.py", line 130, in astep
self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
File "/Users/mark/opt/miniconda3/envs/pymc/lib/python3.6/site-packages/pymc3/step_methods/hmc/quadpotential.py", line 231, in raise_ok
raise ValueError('\n'.join(errmsg))
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `intercept`.ravel()[0] is zero.
"""
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `intercept`.ravel()[0] is zero.
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
<ipython-input-48-56135084a3c4> in <module>
8
9 with linear_model:
---> 10 trace = pm.sample(1000, tune=1000)
After some search, I found out that it could be caused by overflow however I am not sure how I would change the parameters in order to fit the data. There are also no NaN values and the range does not seem to be too large as you can see here: