【问题标题】:Im new on Bayseian Networks and getting a value error what could be the reason?我是 Bayseian Networks 的新手,遇到值错误可能是什么原因?
【发布时间】: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


    【解决方案1】:

    我也遇到同样的问题,如果你解决了,你介意分享一下你是如何解决这个问题的吗?

    谢谢

    【讨论】:

      猜你喜欢
      • 2013-06-25
      • 2011-11-18
      • 2014-10-08
      • 2022-07-01
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多