推荐于2016-10-09 19:33:53
1 2 3 4 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public static void Regular() throws Exception { File inputfile = new File( "F:\\weka\\eucalyptus_Train.arff" ); ArffLoader loader = new ArffLoader(); loader.setFile(inputfile); Instances insTrain = loader.getDataSet(); insTrain.setClassIndex(insTrain.numAttributes()- 1 ); inputfile = new File( "F:\\weka\\eucalyptus_Test.arff" ); loader.setFile(inputfile); Instances insTest = loader.getDataSet(); insTest.setClassIndex(insTest.numAttributes()- 1 ); double sum = insTest.numInstances(); int right = 0 ; Classifier clas = new J48(); //Classifier clas = new weka.classifiers.bayes.BayesNet(); clas.buildClassifier(insTrain); for ( int i = 0 ; i < sum; i++) { if (clas.classifyInstance(insTest.instance(i)) == insTest.instance(i).classValue()) { right++; } System.out.println(clas.classifyInstance(insTest.instance(i))+ " : " +insTest.instance(i).classValue()); } System.out.println( "分类准确率:" +right/sum); } |