Examples of ConfusionMatrix


Examples of cc.mallet.classify.evaluate.ConfusionMatrix

    Classifier me = new MaxEntTrainer().train(trainList);
    ClassifyingNeighborEvaluator eval =
      new ClassifyingNeighborEvaluator(me, "YES");
                                          
    Trial trial = new Trial(me, trainList);
    System.err.println(new ConfusionMatrix(trial));
    InfoGain ig = new InfoGain(trainList);
    ig.print();

//     Clusterer clusterer = new GreedyAgglomerative(training.getInstances().getPipe(),
//                                                   eval, 0.5);
View Full Code Here

Examples of com.aliasi.classify.ConfusionMatrix

      ObjectInputStream oi = new ObjectInputStream( new FileInputStream(modelFile) );
      LMClassifier compiledClassifier = (LMClassifier) oi.readObject();
      oi.close();
     
      //*-- loop through the identical categories and test the classification of test documents
    ConfusionMatrix confMatrix = new ConfusionMatrix(CATEGORIES);
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumIntegerDigits(1); nf.setMaximumFractionDigits(3);
    for (int i=0; i < CATEGORIES.length; ++i)
       {
    File classDir = new File(TESTING_DIR, CATEGORIES[i]);
    String[] testingFiles = classDir.list();
       
        //*-- for each file, find the best category using the classifier and compare with the
        //*-- designated category
    for (int j = 0; j < testingFiles.length; ++j)
         {
      String text = Files.readFromFile( new File(classDir, testingFiles[j]) );
      logger.debug("Testing on " + CATEGORIES[i] + File.separator + testingFiles[j]);
      JointClassification jc =  compiledClassifier.classifyJoint(text);
          confMatrix.increment(CATEGORIES[i], jc.bestCategory());
          logger.debug("Best Category: " + jc.bestCategory() );
          StringBuffer sb = new StringBuffer();
          sb.append("Scores ");
          for (int k = 0; k < CATEGORIES.length; k++) sb.append(nf.format(jc.score(k)) + " ");
          logger.debug(sb);
     } //*-- end of inner for
    } //*-- end of outer for
     
      logger.info("--------------------------------------------");
      logger.info("- Results ");
      logger.info("--------------------------------------------");
      int[][] imatrix = confMatrix.matrix();
      StringBuffer sb = new StringBuffer();
      sb.append(StringTools.fillin("CATEGORY", 10, true, ' ') );
      for (int i = 0; i < CATEGORIES.length; i++) sb.append(StringTools.fillin(CATEGORIES[i], 12, true, ' ') );
      logger.info(sb.toString());
     
      for (int i = 0; i < imatrix.length; i++)
      { sb = new StringBuffer();
        sb.append(StringTools.fillin(CATEGORIES[i], 10, true, ' ', 10 - CATEGORIES[i].length() ) );
        for (int j = 0; j < imatrix.length; j++)
         {  String out = "" + imatrix[i][j];
          sb.append(StringTools.fillin(out, 10, false, ' ', 10 - out.length() ) );
         }
        logger.info(sb.toString());
      }
     
    logger.info("Total Accuracy: " + nf.format(confMatrix.totalAccuracy()) );
      logger.info("Total Correct : " + confMatrix.totalCorrect() + " out of " + confMatrix.totalCount() );
    }
View Full Code Here

Examples of com.aliasi.classify.ConfusionMatrix

      ObjectInputStream oi = new ObjectInputStream( new FileInputStream(modelFile) );
      LMClassifier compiledClassifier = (LMClassifier) oi.readObject();
      oi.close();
     
      //*-- loop through the identical categories and test the classification of test documents
    ConfusionMatrix confMatrix = new ConfusionMatrix(CATEGORIES);
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumIntegerDigits(1); nf.setMaximumFractionDigits(3);
    for (int i=0; i < CATEGORIES.length; ++i)
       {
    File classDir = new File(TESTING_DIR, CATEGORIES[i]);
    String[] testingFiles = classDir.list();
       
        //*-- for each file, find the best category using the classifier and compare with the
        //*-- designated category
    for (int j=0; j < testingFiles.length; ++j)
         {
      String text = Files.readFromFile( new File(classDir, testingFiles[j]) );
      logger.debug("Testing on " + CATEGORIES[i] + File.separator + testingFiles[j]);
      JointClassification jc =  compiledClassifier.classifyJoint(text);
          confMatrix.increment(CATEGORIES[i], jc.bestCategory());
          logger.debug("Best Category: " + jc.bestCategory() );
          StringBuffer sb = new StringBuffer();
          sb.append("Scores ");
          for (int k = 0; k < CATEGORIES.length; k++) sb.append(nf.format(jc.score(k)) + " ");
          logger.debug(sb);
     } //*-- end of inner for
    } //*-- end of outer for
     
      logger.info("--------------------------------------------");
      logger.info("- Results ");
      logger.info("--------------------------------------------");
      int[][] imatrix = confMatrix.matrix();
      StringBuffer sb = new StringBuffer();
      sb.append(StringTools.fillin("CATEGORY", 10, true, ' ') );
      for (int i = 0; i < CATEGORIES.length; i++) sb.append(StringTools.fillin(CATEGORIES[i], 8, false, ' ') );
      logger.info(sb.toString());
     
      for (int i = 0; i < imatrix.length; i++)
      { sb = new StringBuffer();
        sb.append(StringTools.fillin(CATEGORIES[i], 10, true, ' ', 10 - CATEGORIES[i].length() ) );
        for (int j = 0; j < imatrix.length; j++)
         {  String out = "" + imatrix[i][j];
          sb.append(StringTools.fillin(out, 8, false, ' ', 8 - out.length() ) );
         }
        logger.info(sb.toString());
      }
     
    logger.info("Total Accuracy: " + nf.format(confMatrix.totalAccuracy()) );
      logger.info("Total Correct : " + confMatrix.totalCorrect() + " out of " + confMatrix.totalCount() );
    }
View Full Code Here

Examples of com.aliasi.classify.ConfusionMatrix

      ObjectInputStream oi = new ObjectInputStream( new FileInputStream(modelFile) );
      LMClassifier compiledClassifier = (LMClassifier) oi.readObject();
      oi.close();
     
      //*-- loop through the identical categories and test the classification of test documents
    ConfusionMatrix confMatrix = new ConfusionMatrix(CATEGORIES);
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumIntegerDigits(1); nf.setMaximumFractionDigits(3);
    for (int i=0; i < CATEGORIES.length; ++i)
       {
    File classDir = new File(TESTING_DIR, CATEGORIES[i]);
    String[] testingFiles = classDir.list();
       
        //*-- for each file, find the best category using the classifier and compare with the
        //*-- designated category
    for (int j=0; j < testingFiles.length; ++j)
         {
      String text = Files.readFromFile( new File(classDir, testingFiles[j]) );
     
      //*-- limit the length of the text
        if (text.length() > 500text = text.substring(0, 500);
      logger.debug("Testing on " + CATEGORIES[i] + File.separator + testingFiles[j]);
      JointClassification jc =  compiledClassifier.classifyJoint(text);
     
      //*-- check if we have sufficient confidence in the decision
      String bestCategory = (jc.score(0) > -2.5) ? jc.bestCategory(): "text";
      confMatrix.increment(CATEGORIES[i], bestCategory)
          logger.debug("Best Category: " + bestCategory );
          StringBuffer sb = new StringBuffer();
          sb.append("Scores ");
          for (int k = 0; k < CATEGORIES.length; k++)
            sb.append(nf.format(jc.score(k)) + " ");
          logger.debug(sb);
     } //*-- end of inner for
    } //*-- end of outer for
     
      logger.info("--------------------------------------------");
      logger.info("- Results ");
      logger.info("--------------------------------------------");
      int[][] imatrix = confMatrix.matrix();
      StringBuffer sb = new StringBuffer();
      sb.append(StringTools.fillin("CATEGORY", 10, true, ' ') );
      for (int i = 0; i < CATEGORIES.length; i++) sb.append(StringTools.fillin(CATEGORIES[i], 8, false, ' ') );
      logger.info(sb.toString());
     
      for (int i = 0; i < imatrix.length; i++)
      { sb = new StringBuffer();
        sb.append(StringTools.fillin(CATEGORIES[i], 10, true, ' ', 10 - CATEGORIES[i].length() ) );
        for (int j = 0; j < imatrix.length; j++)
         {  String out = "" + imatrix[i][j];
          sb.append(StringTools.fillin(out, 8, false, ' ', 8 - out.length() ) );
         }
        logger.info(sb.toString());
      }
     
    logger.info("Total Accuracy: " + nf.format(confMatrix.totalAccuracy()) );
      logger.info("Total Correct : " + confMatrix.totalCorrect() + " out of " + confMatrix.totalCount() );
    }
View Full Code Here

Examples of com.ipeirotis.gal.core.ConfusionMatrix

    for (int i=1; i<5; i++) {
      Category c = new Category("cat"+i);
      categories.add(c);
    }
   
    cm = new ConfusionMatrix(categories);
    cm.empty();
   
    for (String from: cm.getCategoryNames()) {
      for (String to: cm.getCategoryNames()) {
        Double error = Math.random();
View Full Code Here

Examples of org.apache.mahout.classifier.ConfusionMatrix

        symbols.add(pieces[0]);
      }
      line = in.readLine();
    }

    ConfusionMatrix x2 = new ConfusionMatrix(symbols, "unknown");

    in = new BufferedReader(new FileReader(inputFile));
    line = in.readLine();
    while (line != null) {
      String[] pieces = line.split(",");        
      String trueValue = pieces[0];
      String estimatedValue = pieces[1];
      x2.addInstance(trueValue, estimatedValue);     
      line = in.readLine();
    }
    System.out.printf("%s\n\n", x2.toString());
  }
View Full Code Here

Examples of org.apache.mahout.classifier.ConfusionMatrix

   
    client.setConf(conf);
    JobClient.runJob(conf);
   
    Path outputFiles = new Path(outPath.toString() + "/part*");
    ConfusionMatrix matrix = readResult(dfs, outputFiles, conf, params);
    log.info("{}", matrix.summarize());
  }
View Full Code Here

Examples of org.apache.mahout.classifier.ConfusionMatrix

        confusionMatrix.put(correctLabel, rowMatrix);
       
      }
    }
   
    ConfusionMatrix matrix = new ConfusionMatrix(confusionMatrix.keySet(), defaultLabel);
    for (Map.Entry<String,Map<String,Integer>> correctLabelSet : confusionMatrix.entrySet()) {
      Map<String,Integer> rowMatrix = correctLabelSet.getValue();
      for (Map.Entry<String,Integer> classifiedLabelSet : rowMatrix.entrySet()) {
        matrix.addInstance(correctLabelSet.getKey(), classifiedLabelSet.getKey());
        matrix.putCount(correctLabelSet.getKey(), classifiedLabelSet.getKey(), classifiedLabelSet.getValue());
      }
    }
    return matrix;
   
  }
View Full Code Here

Examples of org.apache.mahout.classifier.ConfusionMatrix

            // log.info("{} {}", correctLabel, classifiedLabel);
           
          }
          lineNum++;
        }
        ConfusionMatrix matrix = resultAnalyzer.getConfusionMatrix();
        log.info("{}", matrix);
        BayesClassifierDriver.confusionMatrixSeqFileExport(params, matrix);

        log.info("ConfusionMatrix: {}", matrix.toString());
          
        log.info("Classified instances from {}", file.getName());
        if (verbose) {
          log.info("Performance stats {}", operationStats.toString());
        }
View Full Code Here

Examples of org.apache.mahout.classifier.ConfusionMatrix

   
    client.setConf(conf);
    JobClient.runJob(conf);
   
    Path outputFiles = new Path(outPath, "part*");
    ConfusionMatrix matrix = readResult(outputFiles, conf, params);
    log.info("{}", matrix);
    if (params.get("confusionMatrix") != null) {
      confusionMatrixSeqFileExport(params, matrix);
    }
   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.