Is there a way to plot a Bayesian network with its marginal distributions using BNLearn in Python?

94 views Asked by At

I'm performing inferences with the BNLearn in Python, and would like to create a plot similar to to the attached image. Is it possible?

I tried to use PyAgrum but found it difficult to use. I attempted to use Graphviz, but I was not successful. enter image description here

1

There are 1 answers

0
Pierre-Henri Wuillemin On

Yes there is a way to do so with pyAgrum :

enter image description here

The code :

import pyAgrum as gum
import pyAgrum.lib.notebook as gnb

bn=gum.fastBN("C{a|b|c}->D{a|b|c}<-A{a|b|c}->B{a|b|c}->E{a|b|c}<-F{a|b}")

bn.cpt("A").fillWith(1).normalize()
bn.cpt("C").fillWith([0.743,0.205,0.052])
bn.cpt("F").fillWith([0.502,0.498])
# other cpts are random

gnb.sideBySide(gnb.getBN(bn),gnb.getInference(bn),gnb.getInference(bn,evs={"B":"b"},targets={"B","C","F","E"}))