【发布时间】:2015-06-22 16:40:49
【问题描述】:
这是我的代码,我正在使用 weka API。我想打印错误分类的实例和准确分类的实例。请帮助我,或者告诉我任何其他能够做我想做的事情的文本分类 java API。
public void evaluation() throws Exception{
BufferedReader reader=null;
reader= new BufferedReader(new FileReader("SparseDTM.arff"));
Instances train= new Instances(reader);
train.setClassIndex(0);
train.toSummaryString();
reader.close();
SMO svm=new SMO();
svm.buildClassifier(train);
NaiveBayes nB = new NaiveBayes();
nB.buildClassifier(train);
weka.classifiers.Evaluation eval= new weka.classifiers.Evaluation(train);
eval.crossValidateModel(nB, train,10,new Random(1));
//eval.crossValidateModel(nB, train,10,new Random(1), new Object[] { });
System.out.println("\n\t************Results by Naive Bayes Classifier************\n");
System.out.println(eval.toSummaryString("", true));
System.out.println(eval.toClassDetailsString());
// System.out.println("F Measure: "+eval.fMeasure(1) + " " + "Precision: "+eval.precision(1) + " " + "Precision: "+eval.recall(1));
// System.out.println("Correct :" + eval.correct());
// System.out.println("Weighted True Negative Rate: " + eval.weightedTrueNegativeRate());
// System.out.println("Weighted False Positive Rate:" + eval.weightedFalsePositiveRate());
// System.out.println("Weighted False Negative Rate:" + eval.weightedFalseNegativeRate());
// System.out.println("Weighted True Positive Rate:" + eval.weightedTruePositiveRate());
System.out.println(eval.toMatrixString());
}
【问题讨论】: