Python toolkit for causal and probabilistic reasoning

pgmpy is a Python library for causal and probabilistic reasoning with graphical models. It covers the full workflow from learning causal graphs from data to estimating causal effects, running probabilistic inference, and simulating data from fitted models. All algorithms follow a unified, composable API and are scikit-learn compatible where possible, so they work standalone, in sklearn pipelines, or as building blocks for higher-level tools.

Key Features#

Causal Discovery / Structure Learning

Learn causal graphs from data using scikit-learn compatible implementations.

Causal Discovery / Structure Learning
Parameter Estimation

Estimate conditional distributions for nodes in the model.

Parameter Estimation
Probabilistic Inference

Compute posterior distributions from the learned model using exact or approximate inference.

Probabilistic Inference
Causal Identification

Given a causal graph determine how to estimate the a causal query.

Causal Identification
Causal Inference

Compute interventional and counterfactual distributions from models.

Causal Inference
Example Datasets and Models

Built-in collection of example Bayesian Networks and datasets from different sources.

Example Datasets and Models
Simulations

Simulate data from models under various scenarios.

Simulations
Extend pgmpy

Write your own custom pgmpy plugable methods using our extension templates.

Extend pgmpy