本文整理匯總了Java中weka.classifiers.Evaluation.toMatrixString方法的典型用法代碼示例。如果您正苦於以下問題:Java Evaluation.toMatrixString方法的具體用法?Java Evaluation.toMatrixString怎麽用?Java Evaluation.toMatrixString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weka.classifiers.Evaluation
的用法示例。
在下文中一共展示了Evaluation.toMatrixString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: printClassifierResults
import weka.classifiers.Evaluation; //導入方法依賴的package包/類
/**
* Prints the results stored in an Evaluation object to standard output
* (summary, class results and confusion matrix)
*
* @param Evaluation eval
* @throws Exception
*/
public void printClassifierResults (Evaluation eval) throws Exception
{
// Print the result à la Weka explorer:
String strSummary = eval.toSummaryString();
System.out.println(strSummary);
// Print per class results
String resPerClass = eval.toClassDetailsString();
System.out.println(resPerClass);
// Get the confusion matrix
String cMatrix = eval.toMatrixString();
System.out.println(cMatrix);
System.out.println();
}
示例2: trainClassifier
import weka.classifiers.Evaluation; //導入方法依賴的package包/類
public void trainClassifier(Classifier classifier, File trainingDataset,
FileOutputStream trainingModel, Integer
crossValidationFoldNumber) throws Exception {
CSVLoader csvLoader = new CSVLoader();
csvLoader.setSource(trainingDataset);
Instances instances = csvLoader.getDataSet();
switch(classifier) {
case KNN:
int K = (int) Math.ceil(Math.sqrt(instances.numInstances()));
this.classifier = new IBk(K);
break;
case NB:
this.classifier = new NaiveBayes();
}
if(instances.classIndex() == -1) {
instances.setClassIndex(instances.numAttributes() - 1);
}
this.classifier.buildClassifier(instances);
if(crossValidationFoldNumber > 0) {
Evaluation evaluation = new Evaluation(instances);
evaluation.crossValidateModel(this.classifier, instances, crossValidationFoldNumber,
new Random(1));
kappa = evaluation.kappa();
fMeasure = evaluation.weightedFMeasure();
confusionMatrix = evaluation.toMatrixString("Confusion matrix: ");
}
ObjectOutputStream outputStream = new ObjectOutputStream(trainingModel);
outputStream.writeObject(this.classifier);
outputStream.flush();
outputStream.close();
}
示例3: classifyMyInstances
import weka.classifiers.Evaluation; //導入方法依賴的package包/類
public String classifyMyInstances(Instances inst) throws Exception {
Instances data = inst;
String summary = "";
WekaConfig conf = WekaConfig.getInstance();
String algorithm = conf.getAlgorithm();
Classifier clas = null;
if (conf.isFilterBool()) {
FilterSet filtr = new FilterSet();
switch (conf.getFilter()) {
case "CSF greedy":
data = filtr.filterCFS_Greedy(inst);
break;
case "CSF best first":
data = filtr.filterCFS_BestFirst(inst);
break;
case "Filtered CSF greedy":
data = filtr.filterFilteredCSF_Greedy(inst);
break;
case "Filtered CSF best first":
data = filtr.filterFilteredCSF_BestFirst(inst);
break;
case "Consistency greedy":
data = filtr.filterConsinstency_Greedy(inst);
break;
case "Consistency best first":
data = filtr.filterConsinstency_BestFirst(inst);
break;
}
}
switch (algorithm) {
case "J48":
summary += "J48 \n";
clas = classifyJ48(data);
break;
case "Naive Bayes":
summary += "Naive Bayes \n";
clas = classifyNaiveBayes(data);
break;
case "Lazy IBk":
summary += "Lazy IBk \n";
clas = classifyIBk(data);
break;
case "Random Tree":
summary += "Random Tree \n";
clas = classifyRandomTree(data);
break;
case "SMO":
summary += "SMO \n";
clas = classifySMO(data);
break;
case "PART":
summary += "PART \n";
clas = classifyPART(data);
break;
case "Decision Table":
summary += "Decision Table \n";
clas = classifyDecisionTable(data);
break;
case "Multi Layer":
summary += "Multi Layer \n";
clas = classifyMultiLayer(data);
break;
case "Kstar":
summary += "Kstar \n";
clas = classifyKStar(data);
break;
}
summary += "\n";
summary += "---------Klasifikacja-------------- \n";
summary += clas.toString();
Evaluate eval = new Evaluate();
Evaluation evalu = eval.crossValidation(clas, data, conf.getFolds());
summary += "----------Ewaluacja---------------- \n";
summary += evalu.toSummaryString();
summary += evalu.toMatrixString();
return summary;
}