I am currently working on a project where I have to deal with Bayesian Networks and given the graphical nature of these probabilistic models, it is very essential to visualize them as a graph. I am using pgmpy for my project.
The model I am dealing with has a large number of variables, often having long names as data identifiers. I therefore was contemplating on illustrating the graph with a legend and each node having a 'code' or a 'number', mapping to a data identifier (perhaps a dict could be used).
The edges I have are in the following format:
[('A','B'), ('B', 'C'), ('C','A')]
In other words, an array of 2-tuples of strings.
It would be great if someone could help me in solving this particular issue.
pgmpy
models (at leastBayesianNetwork
s) inherit fromnx.Digraph
s and can be visualized usingnx.draw
, which takes a Matplotlib Axes object as optional parameter. Therefore, one can create an axes object, manually add a legend, hide the handles, relabel the nodes and draw the model.Here is an example using a
dict
(as suggested) for identifier mapping:PS:
[('A','B'), ('B', 'C'), ('C','A')]
) form a cycle (Bayesian Networks are asyclic).nx.draw
raises aStopIteration
exception checkout this question.