gpt4 book ai didi

java - 如何使用 WEKA API 学习贝叶斯网络(结构+参数)?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:28:49 25 4
gpt4 key购买 nike

有谁知道使用 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);

但事实并非如此。我已经尝试了这个和其他变体,但我一直在 WEKA 代码中的某处收到 ArrayIndexOutOfBoundsExceptionNullPointerException,那么我错过了什么?

最佳答案

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

@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

让我提一下,当您的目标属性不是名义上的(例如数字)时,预计会出现异常。当您的所有属性都是名义上的时,贝叶斯网络会更好地工作。如果将目标属性更改为数字,您将收到 NullPointerExceptionArrayIndexOutOfBoundsException。特别是,在以下行抛出此异常:

EditableBayesNet bn = new EditableBayesNet(ins);

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

关于java - 如何使用 WEKA API 学习贝叶斯网络(结构+参数)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6143583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com