java - ArrayIndexOutOfBoundsException in weka.classifiers.Classifier.classifyInstance -


i have written method. want write bayesian network, exception on classifyinstance() method.

here code:

public static double bayesnet1(dataset data, dataset testingset) throws exception {          instances insts = converttxttoarff(data);         k2 learner = new k2();         multinomialbmaestimator estimator = new multinomialbmaestimator();         estimator.setusek2prior(true);          editablebayesnet bn = new editablebayesnet(insts);         bn.initstructure();         learner.buildstructure(bn, insts);         estimator.estimatecpts(bn);          double error = 0;          instances inststest = converttxttoarff(testingset);          for(int i=0; i<inststest.numinstances()-1; i++) {          weka.core.instance inst = inststest.instance(i);          double  predictedvalue = bn.classifyinstance(inst);          if(inst.value(inst.classindex())!= predictedvalue)              error++;          }          return error/inststest.numinstances();     } 

and here exception:

java.lang.arrayindexoutofboundsexception: 4 @ weka.classifiers.bayes.net.estimate.discreteestimatorbayes.getprobability(discreteestimatorbayes.java:106) @ weka.classifiers.bayes.net.estimate.simpleestimator.distributionforinstance(simpleestimator.java:183) @ weka.classifiers.bayes.bayesnet.distributionforinstance(bayesnet.java:386) @ weka.classifiers.classifier.classifyinstance(classifier.java:84) @ ensembleclassifiersv2.ensembleclassifierv2.bayesnet1(ensembleclassifierv2.java:1090) @ ensembleclassifiersv2.ensembleclassifierv2.performing(ensembleclassifierv2.java:800) @ ensembleclassifiersv2.ensembleclassifierv2.main(ensembleclassifierv2.java:1267)

can me wrong?

i have same problem. fault had not set class test data. simple that.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -