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);
}
svm的话,要用一个wlsvm的包。 代码是一样的,就是Classifier class= new J48()这里要用svm的实例