如何可视化用石榴构建的贝叶斯网络模型
How to visualize a Bayesian network model constructed with pomegranate
我想用以下代码可视化用石榴创建的贝叶斯网络。
import math
from pomegranate import *
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
有人知道我如何使用 matplotlib 或 pygraphvis 做到这一点?
df = pd.DataFrame({'A':[0,0,0,1,0], 'B':[0,0,1,0,0], 'C':[1,1,0,0,1], 'D':[0,1,0,1,1]})
print(df)
df.head()
model = BayesianNetwork.from_samples(df.to_numpy(), state_names=df.columns.values, algorithm='exact')
print(model)
我不知道石榴,但如果可以的话,使用 pyAgrum,
import pyAgrum as gum
import pandas as pd
import pyAgrum.lib.notebook as gnb
df = pd.DataFrame({'A':[0,0,0,1,0], 'B':[0,0,1,0,0], 'C':[1,1,0,0,1], 'D':[0,1,0,1,1]})
gum.BNLearner(df).useAprioriSmoothing(1e-5).useScoreLog2Likelihood().learnBN()
在 jupyter 笔记本中 returns :
有关学习的 BN 的更多信息,
bn=gum.BNLearner(df).useAprioriSmoothing(1e-).useScoreLog2Likelihood().learnBN()
gnb.sideBySide(bn,gnb.getInference(bn))
gnb.sideBySide(*[bn.cpt(i) for i in bn.nodes()])
我想用以下代码可视化用石榴创建的贝叶斯网络。
import math
from pomegranate import *
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
有人知道我如何使用 matplotlib 或 pygraphvis 做到这一点?
df = pd.DataFrame({'A':[0,0,0,1,0], 'B':[0,0,1,0,0], 'C':[1,1,0,0,1], 'D':[0,1,0,1,1]})
print(df)
df.head()
model = BayesianNetwork.from_samples(df.to_numpy(), state_names=df.columns.values, algorithm='exact')
print(model)
我不知道石榴,但如果可以的话,使用 pyAgrum,
import pyAgrum as gum
import pandas as pd
import pyAgrum.lib.notebook as gnb
df = pd.DataFrame({'A':[0,0,0,1,0], 'B':[0,0,1,0,0], 'C':[1,1,0,0,1], 'D':[0,1,0,1,1]})
gum.BNLearner(df).useAprioriSmoothing(1e-5).useScoreLog2Likelihood().learnBN()
在 jupyter 笔记本中 returns :
有关学习的 BN 的更多信息,
bn=gum.BNLearner(df).useAprioriSmoothing(1e-).useScoreLog2Likelihood().learnBN()
gnb.sideBySide(bn,gnb.getInference(bn))
gnb.sideBySide(*[bn.cpt(i) for i in bn.nodes()])