Skip to main content

Bayesian Conjugate Models in Python

Project description

Conjugate Models

Ruff Tests PyPI version docs codecov

Bayesian conjugate models in Python

Installation

pip install conjugate-models

Features

Supported Models

Many likelihoods are supported including

  • Bernoulli / Binomial
  • Categorical / Multinomial
  • Poisson
  • Normal (including linear regression)
  • and many more

Basic Usage

  1. Define prior distribution from distributions module
  2. Pass data and prior into model from models modules
  3. Analytics with posterior and posterior predictive distributions
from conjugate.distributions import Beta, BetaBinomial
from conjugate.models import binomial_beta, binomial_beta_predictive

# Observed Data
X = 4
N = 10

# Analytics
prior = Beta(1, 1)
prior_predictive: BetaBinomial = binomial_beta_predictive(n=N, beta=prior)

posterior: Beta = binomial_beta(n=N, x=X, prior=prior)
posterior_predictive: BetaBinomial = binomial_beta_predictive(n=N, beta=posterior) 

From here, do any analysis you'd like!

# Figure
import matplotlib.pyplot as plt

fig, axes = plt.subplots(ncols=2)

ax = axes[0]
ax = posterior.plot_pdf(ax=ax, label="posterior")
prior.plot_pdf(ax=ax, label="prior")
ax.axvline(x=X/N, color="black", ymax=0.05, label="MLE")
ax.set_title("Success Rate")
ax.legend()

ax = axes[1]
posterior_predictive.plot_pmf(ax=ax, label="posterior predictive")
prior_predictive.plot_pmf(ax=ax, label="prior predictive")
ax.axvline(x=X, color="black", ymax=0.05, label="Sample")
ax.set_title("Number of Successes")
ax.legend()
plt.show()

More examples on in the documentation.

Contributing

If you are interested in contributing, check out the contributing guidelines

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conjugate_models-0.11.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

conjugate_models-0.11.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file conjugate_models-0.11.0.tar.gz.

File metadata

  • Download URL: conjugate_models-0.11.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.8.0-1014-azure

File hashes

Hashes for conjugate_models-0.11.0.tar.gz
Algorithm Hash digest
SHA256 0fabe55ceb7106ab3517e33fa2ff38eb382740b437e71e3105f15281c181943a
MD5 6135d10dfeb9967c8947b9e802bc7025
BLAKE2b-256 e8f5297b7ae201f366b6677d299416ebe723f37b1323b297384e5b41df045982

See more details on using hashes here.

File details

Details for the file conjugate_models-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: conjugate_models-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.8.0-1014-azure

File hashes

Hashes for conjugate_models-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f21675f5b6059758ba43b924c8ad317c782852acf21be4fa08df6374e9887cc2
MD5 6df2770c10490da6cb3d29227c6399d8
BLAKE2b-256 ca7024d9d9b5de9bb03c41e226a49980eab00c53430375720432a79e3539011b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page