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, distribution=prior)

posterior: Beta = binomial_beta(n=N, x=x, prior=prior)
posterior_predictive: BetaBinomial = binomial_beta_predictive(n=N, distribution=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.12.1.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conjugate_models-0.12.1-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: conjugate_models-0.12.1.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.3

File hashes

Hashes for conjugate_models-0.12.1.tar.gz
Algorithm Hash digest
SHA256 2c794151e5d903065b4f62eead1238516769c32db9c1008123e2f72085a5f71e
MD5 82286c4b0dfad895bf1499d02655a1b9
BLAKE2b-256 97fd9b9e186c9e676176fcfab941b69f36a49cbbbc0ab540ffe08126a7509271

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for conjugate_models-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca3c7bd4a6e09087ac1bfed5e35165dca13e6086a246479c742f684cbd56d197
MD5 64441c863a67a246f2730c73bdb48abd
BLAKE2b-256 8ba3a2df7b0f8d48c2321a847b1223ee2821aafb74083c57d2fd7fc8d9c61ffc

See more details on using hashes here.

Supported by

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