如何使用 WEKA API 学习贝叶斯网络(结构+参数)?
有谁知道使用 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 代码中的某处收到 ArrayIndexOutOfBoundsException
或 NullPointerException
,那么我错过了什么?
Does anyone know the "proper" procedure to learn a Bayesian Network from data using the WEKA API? I can't find good instructions in the WEKA documentation.
Based on the documentation and what each function is "supposed" to do, I thought this would work:
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);
But it doesn't. I've tried this and other variations and I keep getting ArrayIndexOutOfBoundsException
or NullPointerException
somewhere inside WEKA code, so what am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用。我尝试使用以下数据集:
让我提一下,当您的目标属性不是名义属性(例如数字)时,预计会出现异常。当所有属性均为名义属性时,贝叶斯网络效果更好。如果将目标属性更改为数字,您将收到
NullPointerException
或ArrayIndexOutOfBoundsException
。特别是,此异常会在以下行抛出:您应该首先离散化您的目标类。
It works for me. I tried with the following set of data:
Let me mention that exceptions are expected when your target attribute is not nominal (e.g. numeric). Bayesian Networks work better when all your attributes are nominal. If you change the target attribute to numeric you'll get a
NullPointerException
or anArrayIndexOutOfBoundsException
. In particular, this exception is thrown at the line:You should first discretize your target class.