O'Reilly logo

Building Probabilistic Graphical Models with Python by Kiran R Karkera

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example of Bayesian estimation

In the learn_cpd_Bayesian.ipynb IPython Notebook, we'll use PyMC to estimate the parameters of one CPD from the job interview network, as shown in the following code:

from libpgm.graphskeleton import GraphSkeleton
from libpgm.nodedata import NodeData
from libpgm.discretebayesiannetwork import DiscreteBayesianNetwork
import pandas as pd

from pymc import *
import matplotlib.pyplot as plt
from pymc.Matplot import plot

nd = NodeData()
skel = GraphSkeleton()
jsonpath="job_interview.txt"
nd.load(jsonpath)
skel.load(jsonpath)
skel.toporder()
bn = DiscreteBayesianNetwork(skel, nd)

The CPD that we are trying to learn is the Interview CPD, as shown in the following code:

pd.DataFrame(bn.Vdata['Interview']['cprob']).transpose() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required