Example Notebooks#
A curated set of Jupyter notebooks that demonstrate the most common tasks in pgmpy: building models, learning from data, running inference, and performing causal analysis. Use this page to find a notebook first, then jump to the matching guide or API section for details.
Defining Bayesian Networks#
See the Defining a Custom Model guide for background.
Build a discrete Bayesian Network from scratch.
Define a linear Gaussian Bayesian Network.
Model temporal dependencies with a Dynamic BN.
Specify conditional probability distributions.
Inspect, modify, and validate a BN.
Causal Discovery / Structure Learning#
See the Causal Discovery guide for background.
Learn a graph structure from data.
Learn tree-structured networks efficiently.
Learn a tree-augmented Naive Bayes model.
Incorporate domain constraints into learning.
Parameter Estimation#
See the Parameter Estimation guide for background.
Fit CPDs for a discrete BN.
Estimate parameters for factor graphs.
Probabilistic Inference#
See the Probabilistic Inference guide for background.
Query posterior probabilities with evidence.
Solve the Monty Hall problem with a BN.
Causal Inference#
See the Causal Identification and Causal Estimation guides for background.
Estimate causal effects from data.
Explore causal reasoning via games.
Simulations#
See the Simulations guide for background.
Generate synthetic samples from a BN.
Extending pgmpy#
Add custom models, estimators, or utilities.
Build functional CPDs for hybrid models.
Perform inference using junction trees.
Tutorial Notebooks#
A series of in-depth tutorial notebooks that walk through pgmpy’s core concepts step by step — from probabilistic graphical model basics to real-world applications.
Foundations of probabilistic graphical models.
Build and reason with Bayesian Networks.
Causal reasoning with Bayesian Networks.
Undirected graphical models and Markov Networks.
Variable Elimination, Belief Propagation, and more.
Sampling-based and variational methods.
Linear Gaussian and hybrid models.
Forward, rejection, and likelihood-weighted sampling.
Import and export models in various formats.
Structure and parameter learning end-to-end.
Real-world case study with Italian energy data.