liveBook · Manning

Categorical data

As explained in Causal AI

A categorical variable is a variable whose values are labels from a finite set of categories rather than numerical measurements.

Categorical data represents variables whose values are labels from finite categories rather than numerical measurements. In a causal model, choosing these abstractions carefully matters because analysis depends on how variables are defined and encoded. section 3.1.8

Categorical variables support a discrete modeling workflow:

  • Represent each variable through a finite set of named outcomes. section 3.1.8
  • Fit conditional probability tables as causal Markov kernels. section 3.1.8
  • Read a probability for each outcome after fixing parent-variable values; probabilities for those outcomes sum to 1. section 3.1.8

Transportation choices

A transportation survey encodes variables such as occupation, residence, and transportation choice categorically. For example, given occupation and residence values, a conditional probability table returns probabilities for car, train, or other transportation. 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 a Python workflow that fits categorical data in a Bayesian network and retrieves its learned conditional probability tables. section 3.1.8

How Causal AI covers it

How deep it goes
Connects categorical variables to learned conditional probability tables and explains lookup probabilities, but does not develop encoding methods.
Examples
Uses transportation survey responses and car, train, or other choices conditioned on occupation and residence.
What you can do after
Apply it via pgmpy by fitting a Bayesian network and inspecting its learned conditional probability tables.
How it connects
Connects categorical data to causal graphical models, Bayesian networks, causal Markov kernels, and conditional probability tables.

Also explained in

Compare how 16 books explain 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.