In the job_interview_libpgm.ipynb
IPython Notebook, we will use the libpgm implementation of maximum likelihood estimates to learn the parameters of the CPDs in the job interview network.
Here is the code from libpgm
that loads the CPDs, as shown before:
from libpgm.graphskeleton import GraphSkeleton from libpgm.nodedata import NodeData from libpgm.discretebayesiannetwork import DiscreteBayesianNetwork from libpgm.tablecpdfactor import TableCPDFactor from libpgm.pgmlearner import PGMLearner import pandas as pd nd = NodeData() skel = GraphSkeleton() jsonpath="job_interview.txt" nd.load(jsonpath) skel.load(jsonpath) skel.toporder()
We can create the Bayesian network and get random samples using the following code:
bn = DiscreteBayesianNetwork(skel, nd) samples=bn.randomsample(2000)
In the following code, we instantiate the PGMLearner
class. The discrete_mle_estimateparams
method already knows the structure of the network. As discussed in the earlier...