Bayesian Analysis with Python
上QQ阅读APP看书,第一时间看更新

Flipping coins the PyMC3 way

Let's revisit the coin-flipping problem from Chapter 1, Thinking Probabilistically, but this time using PyMC3. We will use the same synthetic data we used in that chapter. Since we are generating the data, we know the true value of , called theta_real, in the following code. Of course, for a real dataset, we will not have this knowledge:

np.random.seed(123)
trials = 4
theta_real = 0.35 # unknown value in a real experiment
data = stats.bernoulli.rvs(p=theta_real, size=trials)