7

有谁知道使用 WEKA API 从数据中学习贝叶斯网络的“正确”程序?我在 WEKA 文档中找不到好的说明。

根据文档和每个功能“应该”做什么,我认为这会起作用:

Instances ins = DataSource.read( filename );
ins.setClassIndex(0);

K2 learner = new K2();

MultiNomialBMAEstimator estimator = new MultiNomialBMAEstimator();
estimator.setUseK2Prior(true);

EditableBayesNet bn = new EditableBayesNet( ins );
bn.initStructure();

learner.buildStructure(bn, ins);
estimator.estimateCPTs(bn);

但事实并非如此。我已经尝试过这个和其他变体,并且我不断得到ArrayIndexOutOfBoundsExceptionNullPointerException在 WEKA 代码中的某个地方,所以我错过了什么?

4

1 回答 1

5

这个对我有用。我尝试使用以下数据集:

@relation test

@attribute x {0,1}
@attribute y {0,1,2}
@attribute z {0,1}

@data
0,1,0
1,0,1
1,1,1
1,2,1
0,0,0

让我提一下,当您的目标属性不是名义上的(例如数字)时,会出现异常。当您的所有属性都是标称时,贝叶斯网络会更好地工作。如果您将目标属性更改为数字,您将获得 aNullPointerExceptionArrayIndexOutOfBoundsException. 特别是,在以下行引发了此异常:

EditableBayesNet bn = new EditableBayesNet(ins);

您应该首先离散化您的目标类。

于 2011-05-26T20:44:11.597 回答