python - 在 Python Pomegranate 中,如何创建具有伯努利分布的贝叶斯模型?
问题描述
我正在尝试使用伯努利分布在石榴中创建贝叶斯模型,但我不知道如何构建分布并创建条件表。我已经看到了石榴的 Monty Hall 示例,并试图效仿它。以下是我对此事的看法:
from pomegranate import BernoulliDistribution
from pomegranate import ConditionalProbabilityTable
from pomegranate import Node
from pomegranate import BayesianNetwork
model = BayesianNetwork
c1 = BernoulliDistribution(0.2)
c2 = BernoulliDistribution(0.2 * 4)
pCPT = cpt([
[True, True, 0.25],
[True, False, 0.75],
[False, True, 0.0],
[False, False, 1]
], parents=[c1, c2])
s1 = Node(c1, name="c1")
s2 = Node(c2, name="c2")
s3 = Node(pCPT, name="CPT")
model.add_nodes(s1, s2, s3)
model.add_edge(s1, s3)
model.add_edge(s2, s3)
model.bake()
这给了我以下错误:
AttributeError: 'pomegranate.distributions.BernoulliDistribution.Be' object has no attribute 'keys'
解决方案
推荐阅读
- python-3.x - 在 Jupyterlab 中更改 IOPub 数据速率
- c# - 使用存储库 MVC 添加/插入数据
- swift - 我需要检测蒙面精灵中的触摸而不是(矩形蒙面但 alpha 蒙版)
- r - 仅提取末尾没有句点的行
- c# - EnableSwagger routeTemplate 参数的用途是什么?
- angular-cli - Angular cli不会启动新项目
- python - 将值分配给熊猫数据框中的不可散列列表
- c# - 尝试捕捉论点
- python - 按标签系列重新索引 DataFrame 列
- jhipster - Maven如何设置应用占位符#spring.profiles.active#