List of usage examples for weka.classifiers Evaluation toSummaryString
public String toSummaryString(boolean printComplexityStatistics)
From source file:adams.flow.transformer.WekaEvaluationSummary.java
License:Open Source License
/** * Executes the flow item./*from w w w . j a va 2s. c o m*/ * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; Evaluation eval; StringBuilder buffer; boolean prolog; String[] comment; result = null; if (m_InputToken.getPayload() instanceof WekaEvaluationContainer) eval = (Evaluation) ((WekaEvaluationContainer) m_InputToken.getPayload()) .getValue(WekaEvaluationContainer.VALUE_EVALUATION); else eval = (Evaluation) m_InputToken.getPayload(); buffer = new StringBuilder(); prolog = false; // comments if (m_Comment.getValue().length() > 0) { comment = m_Comment.getValue().split("\n"); if (comment.length == 1) { buffer.append("Comment: " + m_Comment + "\n"); } else { buffer.append("Comment:\n"); for (String line : comment) buffer.append(line + "\n"); } prolog = true; } // relation name if (m_OutputRelationName) { buffer.append("Relation: " + eval.getHeader().relationName() + "\n"); prolog = true; } // separator if (prolog) buffer.append("\n"); // summary if (m_TitleSummary.isEmpty()) buffer.append(eval.toSummaryString(m_ComplexityStatistics)); else buffer.append(eval.toSummaryString(Utils.unbackQuoteChars(m_TitleSummary), m_ComplexityStatistics)); // confusion matrix if (m_ConfusionMatrix) { try { buffer.append("\n\n"); if (m_TitleMatrix.isEmpty()) buffer.append(eval.toMatrixString()); else buffer.append(eval.toMatrixString(Utils.unbackQuoteChars(m_TitleMatrix))); } catch (Exception e) { result = handleException("Failed to generate confusion matrix: ", e); } } // class details if (m_ClassDetails) { try { buffer.append("\n\n"); if (m_TitleClassDetails.isEmpty()) buffer.append(eval.toClassDetailsString()); else buffer.append(eval.toClassDetailsString(Utils.unbackQuoteChars(m_TitleClassDetails))); } catch (Exception e) { result = handleException("Failed to generate class details: ", e); } } m_OutputToken = new Token(buffer.toString()); return result; }
From source file:NaiveBayes.NaiveBayes.java
/** * @param args the command line arguments * @throws java.io.IOException/*from www . jav a 2 s . c o m*/ */ public static void main(String[] args) throws IOException, Exception { System.out.print("1. Buat Model \n"); System.out.print("2. Load Model\n"); System.out.print("Masukkan pilihan : "); Scanner sc = new Scanner(System.in); int pil = sc.nextInt(); System.out.print("Masukkan nama file : "); String filename = sc.next(); DataSource source = new DataSource(("D:\\Program Files\\Weka-3-8\\data\\" + filename)); Instances train = source.getDataSet(); for (int i = 0; i < train.numAttributes(); i++) System.out.println(i + ". " + train.attribute(i).name()); System.out.print("Masukkan indeks kelas : "); int classIdx = sc.nextInt(); train.setClassIndex(classIdx); // MultilayerPerceptron mlp = new MultilayerPerceptron(train, 0.1, 10000, 14); // mlp.buildClassifier(train); // Evaluation eval = new Evaluation (train); //// eval.evaluateModel(mlp, train); // System.out.println(eval.toSummaryString()); NaiveBayes tb = new NaiveBayes(); Evaluation eval = new Evaluation(train); switch (pil) { case 1: // tb.buildClassifier(train); // tb.toSummaryString(); // eval.evaluateModel(tb, train); eval.crossValidateModel(tb, train, 10, new Random(1)); System.out.println(eval.toSummaryString(true)); System.out.println(eval.toMatrixString()); //saveModel(tb); break; default: tb = loadModel(); tb.toSummaryString(); eval.crossValidateModel(tb, train, 10, new Random(1)); System.out.println(eval.toSummaryString()); // System.out.println(eval.toMatrixString()); } }
From source file:nl.detoren.ijc.neural.Voorspeller.java
License:Open Source License
/** * Evalueer trainingsdata//from w ww. j a v a 2 s . c o m * * @param data * @return * @throws Exception */ private Evaluation evaluateTrainingData(Instances data) throws Exception { mlp.buildClassifier(data); Evaluation eval = new Evaluation(data); eval.evaluateModel(mlp, data); logger.log(Level.INFO, eval.toSummaryString(true)); return eval; }