BAyesian Model Building Interface in Python
Actively maintained. Last release 3 months ago, commits in 12 of the last 26 weeks. A safe choice.
pip install bambi
BAyesian Model-Building Interface in Python
Overview
Bambi is a high-level Bayesian model-building interface written in Python. It's built on top of the PyMC probabilistic programming framework, and is designed to make it extremely easy to fit mixed-effects models common in social sciences settings using a Bayesian approach.
Installation
Bambi requires a working Python interpreter (3.12+). We recommend installing Python and key numerical libraries using the Anaconda Distribution, which has one-click installers available on all major platforms.
Assuming a standard Python environment is installed on your machine (including pip), Bambi itself can be installed in one line using pip:
pip install bambi
Alternatively, if you want the bleeding edge version of the package you can install from GitHub:
pip install git+https://github.com/bambinos/bambi.git
Dependencies
Bambi requires working versions of ArviZ, formulae, NumPy, pandas and PyMC. Dependencies are listed in pyproject.toml and should all be installed by the Bambi installer; no further action should be required.
Examples
In the following two examples we assume the following basic setup
import arviz as az
import bambi as bmb
import numpy as np
import pandas as pd
Linear regression
A simple fixed effects model is shown in the example below.
# Read in a dataset from the package content
data = bmb.load_data("sleepstudy")
# See first rows
data.head()
# Initialize the fixed effects only model
model = bmb.Model('Reaction ~ Days', data)
# Get model description
print(model)
# Fit the model using 1000 on each chain
results = model.fit(draws=1000)
# Key summary and diagnostic info on the model parameters
az.summary(results)
# Use ArviZ to plot the results
az.plot_trace(results)