You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Title: Simplest example of PyMC to understand its working on a toy dataset (e.g., a coin flip model)
Why should this notebook be added to pymc-examples?
This notebook aims to provide a highly accessible and transparent example for beginners to understand the fundamental structure of a PyMC model. It demonstrates a single-parameter inference (e.g., coin flip probability) using PyMC, making it an excellent starting point for newcomers.
`
import pymc as pm
import numpy as np
import matplotlib.pyplot as plt
with pm.Model() as model:
# Prior: Assume the probability of heads follows a Beta distribution (uniform prior, so alpha=1, beta=1)
p = pm.Beta('p', alpha=1, beta=1)
# Step 2: Define the Likelihood: This is a Bernoulli distribution based on the coin flips
obs = pm.Bernoulli('obs', p=p, observed=data)
# Step 3: Inference: Draw samples from the posterior distribution using MCMC
trace = pm.sample(2000, return_inferencedata=False)
Step 4: Visualize the posterior distribution of 'p' (the probability of heads)
pm.plot_posterior(trace, var_names=['p'])
plt.title('Posterior distribution of the probability of heads')
plt.show()
`
[Beginner Tutorials]: If existing beginner-level examples cover complex or multi-parameter models, this notebook will focus on a simple, single-parameter inference (e.g., Bernoulli trials for coin flips).
[Modeling Probabilistic Inference]: Can reference as a foundation to build intuition about more complex models.
Notebook proposal
Title: Simplest example of PyMC to understand its working on a toy dataset (e.g., a coin flip model)
Why should this notebook be added to pymc-examples?
This notebook aims to provide a highly accessible and transparent example for beginners to understand the fundamental structure of a PyMC model. It demonstrates a single-parameter inference (e.g., coin flip probability) using PyMC, making it an excellent starting point for newcomers.
`
import pymc as pm
import numpy as np
import matplotlib.pyplot as plt
Data: 10 coin flips with 7 heads (1 = heads, 0 = tails)
data = np.array([1, 1, 1, 1, 0, 1, 1, 0, 1, 0])
Step 1: Define a PyMC Model
with pm.Model() as model:
# Prior: Assume the probability of heads follows a Beta distribution (uniform prior, so alpha=1, beta=1)
p = pm.Beta('p', alpha=1, beta=1)
Step 4: Visualize the posterior distribution of 'p' (the probability of heads)
pm.plot_posterior(trace, var_names=['p'])
plt.title('Posterior distribution of the probability of heads')
plt.show()
`
Suggested categories:
Related notebooks
[Beginner Tutorials]: If existing beginner-level examples cover complex or multi-parameter models, this notebook will focus on a simple, single-parameter inference (e.g., Bernoulli trials for coin flips).
[Modeling Probabilistic Inference]: Can reference as a foundation to build intuition about more complex models.
References
PyMC documentation: https://www.pymc.io/projects/examples/en/latest/
Probability theory and Bayesian inference resources for beginners.
The text was updated successfully, but these errors were encountered: