【问题标题】:How to print the printing full cpd from pgmpy?如何从 pgmpy 打印打印的完整 cpd?
【发布时间】:2022-06-21 15:15:24
【问题描述】:

我正在尝试让Insurance data representation with Bayesian networks 中的示例工作。见章节 最大似然估计。我从 R 中的 bnlearn 包中获得的数据,然后将其上传到我的谷歌驱动器。 The data

下图显示...我相信这显示了缺少的列。如何修复代码以显示正确的信息?

from pgmpy.models import BayesianModel

model = BayesianModel([('Antilock', 'Accident'), ('DrivingSkill', 'DrivQuality'), ('DrivQuality', 'Accident')])

# Maximum Likelihood Estimation
from pgmpy.estimators import MaximumLikelihoodEstimator 
mle = MaximumLikelihoodEstimator(model, df)

# Pour toutes les variables :
model.fit(df, estimator=MaximumLikelihoodEstimator)
for cpd in model.get_cpds():
  print(cpd)

注意1:从R获取数据的代码

data(insurance)

write.csv(insurance,"C:/Users/Administrator/OneDrive/University of London/AI/Assignment 1/insurance.csv")

注意2:如果你在 colab 中运行它,你需要安装包

!pip install pgmpy

【问题讨论】:

    标签: python google-colaboratory pgmpy


    【解决方案1】:
    1. 打开文件“pgmpy/factors/discrete/CPD.py”

    1. 在“TabularCPD(DiscreteFactor)”类中,

      细化“cdf_str = self._truncate_strtable(cdf_str)”这一行

      (这一行在"def _make_table_str (~)")


    1. cdf_str = self._truncate_strtable(cdf_str)

      通过添加“#”使该行停用 --> # cdf_str = self._truncate_strtable(cdf_str)

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 2016-05-27
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多