Please see the full documentation of pgmpy here: http://pgmpy.org/
Exercise 1 (20 points)
Download the 'insurance' network file from the bnlearn repo: http://www.bnlearn.com/bnrepository/insurance/insurance.bif.gz
You'll need to decompress the file and then use the BIFreader module from pgmpy to read the file in as a BayesianNetwork instance.
Print the list of nodes and the list of edges.
In [ ]:
Exercise 2 (40 points)
The first cell below imports the packages that aid in visualization of graphs. The second cell provides sample code to print the entire network. It's not very pretty, so the third cell displays the network using different code (not shown). In this exercise, you will explore trails, and create a subgraph that you can illustrate using the visualization tools.
Note that an 'immorality' is a v-structure X -> Z <- Y, if there is no edge between X and Y. Use the get_immoralities method, along with is_active_trail to find all the v-structures in the insurance model
Create a subgraph that includes the nodes: 'Antilock','Mileage','CarValue','RuggedAuto','Accident','Airbag','Cushioning' and 'MakeModel'
In [4]:
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
import pygraphviz as pgv
In [5]:
nx.draw(insurance_model,node_size=1000,font_size=8,with_labels='TRUE',
pos=graphviz_layout(insurance_model,prog='dot'))
In [5]:
from IPython.display import Image
Image("insurance.png")
Out[5]:
In [ ]:
Exercise 3 (40 points)
Get the cancer network from bnlearn: http://www.bnlearn.com/bnrepository/cancer/cancer.bif.gz.
In [ ]: