Giter Site home page Giter Site logo

bayesian-modeling-with-pymc's Introduction

Bayesian Modeling with PyMC - Probabilistic Python

Probabilistic programming

Probabilistic programming is a paradigm that combines the techniques of probability theory with programming to create models that can reason and make decisions under uncertainty. This approach allows developers to build complex statistical models that can represent uncertain situations and make inferences from data. This repository aims to introduce probabilistic programming using Bayesian Modeling with PyMC.

Bayes' theorem provides the mathematical framework for updating beliefs.



$$ P(\theta \mid D) = \frac{P(D \mid \theta) P(\theta)}{P(D)} $$



For common defitions using this approach visit the DEFINITIONS.md file.

About PyMC

PyMC is used for fitting Bayes' statistical models primarily with Markov chain Monte Carlo. PyMC strives to make Bayesian modeling as simple and painless as possible, allowing users to focus on their problem rather than the methods. Visit the PyMC docs to learn more.

Running the coin_flip.py Script

To run the script, make sure you have pymc, arviz, and matplotlib installed.

pip install pymc arviz matplotlib

Then, run the script:

python coin_flip.py

This will display the posterior distribution of θ (the probability of heads) and print a summary, which includes statistics like the mean, standard deviation, and credible intervals of the posterior distribution.

Explanation

  1. Import Libraries:
  • pymc for Bayesian modeling.
  • matplotlib.pyplot for plotting.
  • arviz for plotting and summarizing the results.
  1. Simulated Data:
  • We simulate 10 coin tosses, with 7 heads (1s) and 3 tails (0s).
  1. Model Definition:
  • We define a PyMC model using a context manager (with pm.Model() as model).
  • Prior: We use a Beta distribution with parameters

$$ \alpha = 1 \quad \text{and} \quad \beta = 1 $$


which is a uniform prior for the probability of heads (θ).

  • Likelihood: We model the observed data as a Bernoulli distribution with parameter θ.
  1. Bayesian Inference:
  • We run the MCMC sampler (pm.sample(1000)) to generate samples from the posterior distribution.
  1. Plot and Summary:
  • We use az.plot_trace(trace) to visualize the posterior distribution.

  • We print a summary of the posterior distribution using az.plot_trace(trace).

bayesian-modeling-with-pymc's People

Contributors

kellymore avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.