用于绘制结构并插入贝叶斯网络的条件概率的库?

发布于 2025-02-06 01:14:46 字数 503 浏览 0 评论 0原文

我正在尝试绘制贝叶斯网络的结构,但是我无法手工卷入条件概率。 我尝试了Bnlearn,Pomgranate ...有人知道可以允许我的图书馆吗?

import pandas as pd
from pomegranate import *
import bnlearn

edges = [
     ('A', 'B'),
    ("B", "C"),
    ("C", "D")]

DAG = bn.make_DAG(edges, verbose =0)
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]})
df.head()

model = BayesianNetwork.from_samples(df.to_numpy(), state_names=df.columns.values, algorithm='exact')
print(model)

有人知道如何在变量之间添加条件概率?

I am trying to draw the structure of a bayesian network and but I can't wirte by hand the conditional probability.
I have trying bnlearn, pomgranate... someone know a library that will allow me?

import pandas as pd
from pomegranate import *
import bnlearn

edges = [
     ('A', 'B'),
    ("B", "C"),
    ("C", "D")]

DAG = bn.make_DAG(edges, verbose =0)
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]})
df.head()

model = BayesianNetwork.from_samples(df.to_numpy(), state_names=df.columns.values, algorithm='exact')
print(model)

Someone know how I can add the conditional probability between the variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉栀 2025-02-13 01:14:48

我认为其中许多人有办法做到这一点。您可以尝试例如pyagrum( https://agrum.org )。

import pyAgrum as gum

# create the Bayesian network
bn=gum.BayesNet()

#nodes (binary by default)
bn.add("s")
bn.add("c")

#arcs
bn.addArc("c","s")

#cpts
bn.cpt("c")[:]=[0.1,0.9]
bn.cpt("s")[:]=[ [0.5,0.5],[0.9,0.1]]

有关更多信息,请参见笔记本: https:///pyagrum.readagrum.readthedocs.io/en en en en /1.1.1/notebooks.html

I think that many of them have a way to do that. You can try for instance pyAgrum (https://agrum.org).

import pyAgrum as gum

# create the Bayesian network
bn=gum.BayesNet()

#nodes (binary by default)
bn.add("s")
bn.add("c")

#arcs
bn.addArc("c","s")

#cpts
bn.cpt("c")[:]=[0.1,0.9]
bn.cpt("s")[:]=[ [0.5,0.5],[0.9,0.1]]

For more, see the notebooks : https://pyagrum.readthedocs.io/en/1.1.1/notebooks.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文