How to find out Bayesian network (structure + parameters) using WEKA API?

Does anyone know the “correct” procedure to find out a Bayesian network from data using the WEKA API? I cannot find good instructions in the WEKA documentation.

Based on the documentation and on what each function “should” 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 this is not so. I tried this and other options, and I keep getting ArrayIndexOutOfBoundsException or NullPointerException somewhere inside the WEKA code, so what am I missing?

+6
source share
1 answer

This works for me. I tried with the following dataset:

 @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 

Let me mention that exceptions are expected when your target attribute is not nominal (e.g. numeric). Bayesian networks work best when all your attributes are nominal. If you change the target attribute to numeric, you will get a NullPointerException or ArrayIndexOutOfBoundsException . In particular, this exception is thrown on the line:

 EditableBayesNet bn = new EditableBayesNet(ins); 

You must discretize your target class first.

+5
source

Source: https://habr.com/ru/post/889144/


All Articles