Bayesian machine learning

Infer coin bias


In [1]:
import pymc
import numpy as np
data = np.array([1, 1, 1, 1, 1, 1, 1, 0, 1])
beta = pymc.Beta('beta', 1, 1)
ber = pymc.Bernoulli('ber', beta, observed = True, value = data)

mcmc = pymc.MCMC([beta, ber])
mcmc.sample(1000, 500, 1)
np.mean(mcmc.trace("beta")[:])


 [-----------------100%-----------------] 1000 of 1000 complete in 0.0 sec
Out[1]:
0.81756653237067389

In [ ]: