【发布时间】:2022-10-14 10:05:27
【问题描述】:
我正在尝试设计一个贝叶斯网络模型,这就是我到目前为止所做的并得到了那个错误。
exam_cpd = TabularCPD(
variable = 'Exam',
variable_card = 3,
values = [
[0.5, 0.8, 0.8, 0.9],
[0.3, 0.15, 0.1, 0.08],
[0.2, 0.05, 0.1, 0.02]
],
evidence = ['Intelligence', 'Hardwork'],
evidence_card = [2,2])
university_exam_model.add_cpds(exam_cpd)
print(exam_cpd)
get_in_university_cpd = TabularCPD(
variable = 'GetInUniversity',
variable_card = 2,
values = [
[0.95, 0.8, 0.5],
[0.05, 0.2, 0.5]
],
evidence = ['Exam'],
evidence_card = [3])
university_exam_model.add_cpds(get_in_university_cpd)
print(get_in_university_cpd)
我收到此错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/var/folders/4b/w8h_fm810bg8c54zcty9zgg40000gn/T/ipykernel_92974/992945167.py in <module>
9 evidence_card = [3])
10
---> 11 university_exam_model.add_cpds(get_in_university_cpd)
12 print(get_in_university_cpd)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pgmpy/models/BayesianNetwork.py in add_cpds(self, *cpds)
256
257 if set(cpd.scope()) - set(cpd.scope()).intersection(set(self.nodes())):
--> 258 raise ValueError("CPD defined on variable not in the model", cpd)
259
260 for prev_cpd_index in range(len(self.cpds)):
ValueError: ('CPD defined on variable not in the model', <TabularCPD representing P(GetInUniversity:2 | Exam:3) at 0x7fca78f3c070>)
我能做些什么来解决这个问题是关于“evidence_card”变量或其他东西,已经搜索过它但在互联网上没有什么。
【问题讨论】:
标签: python deep-learning artificial-intelligence modeling bayesian-networks