liveBook · Manning

BayesianNetwork

As explained in Causal AI

BayesianNetwork is a pgmpy class for representing a Bayesian network and its probabilistic dependencies.

A BayesianNetwork represents a directed dependency structure for categorical variables, then fits the associated conditional probability tables from observed data. In pgmpy, edges encode relationships such as A→E, E→O, and O→T; the model stores each node’s conditional distribution. section 3.1.8

A practical workflow is:

  • Choose variables whose definitions match the inference problem, rather than treating spreadsheet columns as automatically meaningful abstractions. section 3.1.8
  • Construct the network with directed edges, call fit(data), and retrieve learned distributions with get_cpds(). section 3.1.8
  • Interpret each TabularCPD as a conditional probability table whose outcomes sum to one for every parent-value combination. section 3.1.8

Transportation choice model

A fitted network can represent P(T | O,R), where transportation choice T depends on occupation O and resources R. For each O and R combination, probabilities for car, other, and train sum to one. section 3.1.8

Listing 3.4 Learning parameters for the causal Markov kernels
from pgmpy.models import BayesianNetwork
model = BayesianNetwork(
      [
        ('A', 'E'),
        ('S', 'E'),
        ('E', 'O'),
        ('E', 'R'),
        ('O', 'T'),
        ('R', 'T')
     ]
)
model.fit(data)    #1
causal_markov_kernels = model.get_cpds()     #2
print(causal_markov_kernels)  #2

Inspect the Python construction, fitting, and CPD-retrieval workflow for a categorical causal model. section 3.1.8

How Causal AI covers it

How deep it goes
Explains graph construction, fitting, CPD retrieval, and table interpretation, but does not detail inference algorithms.
Examples
Uses a transportation survey and models occupation, resources, and transportation choices with learned probability tables.
What it assumes
Assumes awareness of variables and tabular data while teaching how their definitions affect the resulting model.
What you can do after
Operate/configure a pgmpy model, fit it to categorical data, and inspect its learned conditional probability distributions.
How it connects
Connects Bayesian networks to causal DAGs, causal Markov kernels, conditional probability tables, and categorical data.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.