Markov Chain Monte Carlo in Python | Towards Data Science
mcmcbayesian-inferencepythonprobabilistic-modeling
Abstraction: Complete real-world MCMC implementation using PyMC3 on sleep data
Key points:
- MCMC is a class of methods for sampling from a probability distribution to construct the most likely distribution; used when exact posterior is intractable
- The Metropolis-Hastings algorithm draws random parameter values, accepts them if consistent with observed data, and rejects otherwise — a random walk converging to the true distribution
- Author models sleep/wake transitions with logistic functions; parameters alpha and beta learned via MCMC on ~60 nights of Garmin sleep data (11,340 expanded data points)
- Standard practice is to discard up to 50–90% of initial trace as burn-in; 10,000 samples used here
- PyMC3 library abstracts most MCMC details; autocorrelation plots used to assess convergence
- Model outputs probabilities: 50% sleep probability reached at 10:14 PM, most likely sleep duration 7.67 hours
Connections: Pymc3 · Markov Chain Monte Carlo · Bayesian Inference · Probabilistic Modeling
Source: https://towardsdatascience.com/markov-chain-monte-carlo-in-python-44f7e609be98