Key Word(s): ??



Title :

Bayes - Exercise 1

Description :

Model y as normal distribution with unknown mean and std dev, ignoring x

  • After completing this exercise you should see following trace plots:

Hints:

pymc3 Normal

Refer to lecture notebook.

Do not change any other code except the blanks.

In [1]:
import pandas as pd
import numpy as np

import pymc3 as pm
import warnings
warnings.filterwarnings('ignore')

from matplotlib import pyplot
%matplotlib inline
In [2]:
df = pd.read_csv('data3.csv')
df.head()
Out[2]:
x y
0 2.875775 0.223825
1 7.883051 6.118438
2 4.089769 2.167730
3 8.830174 5.868317
4 9.404673 7.333365
In [0]:
### edTest(test_pm_model) ###
np.random.seed(109)
with pm.Model() as model:
   #Set priors for unknown model parameters
   alpha = pm.Normal('alpha',mu=0,tau=1000)
   
   # Likelihood (sampling distribution) of observations
   tau_obs = pm.Gamma('tau', alpha=0.001, beta=0.001)
   obs = pm.Normal(____________) #Parameters to set: name, mu, tau, observed
   # create trace plots 
   trace = pm.sample(2000, tune=2000)
   pm.traceplot(trace, compact=False);
In [0]:
#posterior means
np.mean(trace['alpha']) , np.mean(trace['tau'])
In [0]:

In [0]: