List of usage examples for weka.classifiers Evaluation toMatrixString
public String toMatrixString() throws Exception
From source file:myclassifier.naiveBayes.java
public void CrossValidation() throws Exception { if (data != null) { Instances train = data;//from w w w .ja v a2s. co m // train classifier NBClassifier.buildClassifier(train); // evaluate classifier and print some statistics Evaluation eval = new Evaluation(train); eval.crossValidateModel(NBClassifier, train, 10, new Random(1)); System.out.println(eval.toSummaryString("\nResults\n======\n", false)); System.out.println(eval.toClassDetailsString("\n=== Detailed Accuracy By Class ===\n")); System.out.println(eval.toMatrixString()); } else { System.out.println("Data is null"); } }
From source file:myclassifier.naiveBayes.java
public void PercentageSplit(double percent) throws Exception { // Percent split int trainSize = (int) Math.round(data.numInstances() * percent / 100); int testSize = data.numInstances() - trainSize; Instances train = new Instances(data, 0, trainSize); Instances test = new Instances(data, trainSize, testSize); // train classifier NBClassifier.buildClassifier(train); // evaluate classifier and print some statistics Evaluation eval = new Evaluation(train); eval.evaluateModel(NBClassifier, test); System.out.println(eval.toSummaryString("\nResults\n======\n", false)); System.out.println(eval.toClassDetailsString("\n=== Detailed Accuracy By Class ===\n")); System.out.println(eval.toMatrixString()); }
From source file:NaiveBayes.NaiveBayes.java
/** * @param args the command line arguments * @throws java.io.IOException// w w w. j a v a2s . co 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:naivebayes.NBRun.java
public static void main(String[] args) throws Exception { System.out.println("Naive Bayes Classifier"); Instances data = TucilWeka.readDataSet("C:\\Program Files\\Weka-3-8\\data\\mush_test.arff"); Scanner scan = new Scanner(System.in); Classifier cls;//from w w w .j a va2 s. c o m Instances train = TucilWeka.readDataSet("C:\\Program Files\\Weka-3-8\\data\\mush.arff"); System.out.println("Read or create model? r/c"); if (scan.next().equals("c")) { cls = new NBTubesAI(); cls.buildClassifier(train); TucilWeka.saveModel(train); } else { cls = (NBTubesAI) TucilWeka.readModel(); } Evaluation eval = new Evaluation(data); System.out.println("10 fold cross validate or Full train? c/f"); if (scan.next().equals("c")) { int fold = 10; for (int i = 0; i < data.numAttributes(); i++) { System.out.println(i + ". " + data.attribute(i)); } eval.crossValidateModel(cls, data, fold, new Random(1)); } else { for (int i = 0; i < data.numAttributes(); i++) { System.out.println(i + ". " + data.attribute(i)); } data.deleteWithMissingClass(); try { eval.evaluateModel(cls, data); } catch (java.lang.Exception ex) { eval.crossValidateModel(cls, data, 11, new Random(1)); } } // Classifier cls=new NBTubesAI(); // cls.buildClassifier(data); System.out.println("Hasil evaluasi: "); System.out.println(eval.toSummaryString()); System.out.println(eval.toMatrixString()); System.out.println(eval.toClassDetailsString()); }
From source file:NaiveBayesPckge.NaiveBayesMain.java
public static void printEvaluationSplit(Instances instance) throws Exception { Evaluation eval = new Evaluation(instance); System.out.println("Split Test Result :"); eval.evaluateModel(naive, instance); System.out.println(eval.toSummaryString()); // Summary of Training //System.out.println(eval.toClassDetailsString()); System.out.println(eval.toMatrixString()); }
From source file:NaiveBayesPckge.NaiveBayesMain.java
public static void printEvaluation(Instances instance) throws Exception { Evaluation eval = new Evaluation(instance); Evaluation eval2 = new Evaluation(instance); System.out.println("Full training Result :"); eval.evaluateModel(naive, instance); System.out.println(eval.toSummaryString()); // Summary of Training //System.out.println(eval.toClassDetailsString()); System.out.println(eval.toMatrixString()); System.out.println("10 cross validation Result :"); Random rand = new Random(1); eval2.crossValidateModel(naive, instance, 10, rand); System.out.println(eval2.toSummaryString()); // Summary of Training //System.out.println(eval2.toClassDetailsString()); System.out.println(eval2.toMatrixString()); double errorRates = eval.incorrect() / eval.numInstances() * 100; double accuracy = eval.correct() / eval.numInstances() * 100; // System.out.println("Accuracy: " + df.format(accuracy) + " %"); // System.out.println("Error rate: " + df.format(errorRates) + " %"); // Printing Training Mean root squared error }
From source file:newclassifier.NewClassifier.java
public void crossValidation() throws Exception { cls.buildClassifier(data);//from w w w .ja v a 2s . c om Evaluation eval = new Evaluation(data); eval.crossValidateModel(cls, data, 10, new Random(1)); System.out.println(eval.toSummaryString("\nResults\n======\n", false)); System.out.println(eval.toClassDetailsString()); System.out.println(eval.toMatrixString()); }
From source file:newclassifier.NewClassifier.java
public void givenTestSet(String path) throws Exception { Instances test = DataSource.read(path); test.setClassIndex(test.numAttributes() - 1); cls.buildClassifier(data);//from w w w. ja va 2 s.co m Evaluation eval = new Evaluation(data); eval.evaluateModel(cls, test); System.out.println(eval.toSummaryString("\nResults\n======\n", false)); System.out.println(eval.toClassDetailsString()); System.out.println(eval.toMatrixString()); }
From source file:org.dkpro.similarity.algorithms.ml.ClassifierSimilarityMeasure.java
License:Open Source License
public ClassifierSimilarityMeasure(WekaClassifier classifier, File trainArff, File testArff) throws Exception { CLASSIFIER = getClassifier(classifier); // Get all instances Instances train = getTrainInstances(trainArff); test = getTestInstances(testArff);//from ww w.ja va2 s. c om // Apply log filter Filter logFilter = new LogFilter(); logFilter.setInputFormat(train); train = Filter.useFilter(train, logFilter); logFilter.setInputFormat(test); test = Filter.useFilter(test, logFilter); Classifier clsCopy; try { // Copy the classifier clsCopy = AbstractClassifier.makeCopy(CLASSIFIER); // Build the classifier filteredClassifier = clsCopy; filteredClassifier.buildClassifier(train); Evaluation eval = new Evaluation(train); eval.evaluateModel(filteredClassifier, test); System.out.println(eval.toSummaryString()); System.out.println(eval.toMatrixString()); } catch (Exception e) { throw new SimilarityException(e); } }
From source file:org.processmining.analysis.clusteranalysis.DecisionAnalyzer.java
License:Open Source License
/** * Creates an evaluation overview of the built classifier. * //w ww.j av a 2 s. c o m * @return the panel to be displayed as result evaluation view for the * current decision point */ protected JPanel createEvaluationVisualization(Instances data) { // build text field to display evaluation statistics JTextPane statistic = new JTextPane(); try { // build evaluation statistics Evaluation evaluation = new Evaluation(data); evaluation.evaluateModel(myClassifier, data); statistic.setText(evaluation.toSummaryString() + "\n\n" + evaluation.toClassDetailsString() + "\n\n" + evaluation.toMatrixString()); } catch (Exception ex) { ex.printStackTrace(); return createMessagePanel("Error while creating the decision tree evaluation view"); } statistic.setFont(new Font("Courier", Font.PLAIN, 14)); statistic.setEditable(false); statistic.setCaretPosition(0); JPanel resultViewPanel = new JPanel(); resultViewPanel.setLayout(new BoxLayout(resultViewPanel, BoxLayout.PAGE_AXIS)); resultViewPanel.add(new JScrollPane(statistic)); return resultViewPanel; }