简体   繁体   English

在python中为libpgm包使用json格式文件

[英]using a json format file for libpgm package in python

I'm a new programmer with python. 我是python的新程序员。 I want to use bayesian network for classification. 我想使用贝叶斯网络进行分类。 Therefore i'm using libpgm package in python.The first codes for using this package is: 因此,我在python中使用libpgm软件包。使用此软件包的第一个代码是:

from libpgm.nodedata importNodeData
from libpgm.graphskeleton importGraphSkeleton
from libpgm.discretebayesiannetwork importDiscreteBayesianNetwork
from libpgm.pgmlearner importPGMLearner

nd=NodeData()
skel=GraphSkeleton()
fpath="json.txt"
nd.load(fpath)
skel.load(fpath)

The problem is that i don't know anything about content of this json file and path. 问题是我对这个json文件和路径的内容一无所知。 I have installed Ananconda on my windows. 我已经在Windows上安装了Ananconda。 Is there anyone who can help me? 有谁可以帮助我吗? Is there anyone who have such file for a small bayesian network such as asia? 是否有人为诸如亚洲这样的小型贝叶斯网络提供此类文件? Thanks. 谢谢。

This GitHub repo seems to contain some usage examples and data. 这个GitHub回购似乎包含一些用法示例和数据。

The Code example can be found here . 代码示例可在此处找到。 Try to make it work locally. 尝试使其在本地工作。

The Bayesian network has to be represented as a valid JSON. 贝叶斯网络必须表示为有效的JSON。 So if you have a sufficiently big network, check the JSON formatting (eg using JSONlint) before wasting your time in debugging. 因此,如果您的网络足够大,请在浪费调试时间之前检查JSON格式(例如,使用JSONlint)。 Else nd.load() will give errors. 否则nd.load()将给出错误。

If the network loads but you still get errors is CPD factorization (while using TableCPDFactorization()), check the data again. 如果网络负载很大,但您仍然遇到CPD因式分解错误(使用TableCPDFactorization()时),请再次检查数据。 Eg there should be no space after commas. 例如,逗号后不应有空格。 Even though it will be a valid JSON it will not work due to indexing into the Vdataentry in discretebayesiannetwork.py. 尽管它将是有效的JSON,但由于已在离散bayesiannetwork.py中索引到Vdataentry中,因此将无法使用。 Also check that parents are in correct order in the tables and probabilities are correct. 还要检查父母在表中的顺序是否正确以及概率是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM