Package org.apache.mahout.classifier

Examples of org.apache.mahout.classifier.ClassifierResult


 
  @Override
  public ClassifierResult classifyDocument(String[] document,
                                           Datastore datastore,
                                           String defaultCategory) throws InvalidDatastoreException {
    ClassifierResult result = new ClassifierResult(defaultCategory);
    double max = Double.MIN_VALUE;
    Collection<String> categories = datastore.getKeys("labelWeight");
   
    for (String category : categories) {
      double prob = documentWeight(datastore, category, document);
      if (max < prob) {
        max = prob;
        result.setLabel(category);
      }
    }
    result.setScore(max);
    return result;
  }
View Full Code Here


    PriorityQueue<ClassifierResult> pq = new PriorityQueue<ClassifierResult>(numResults,
        new ByScoreLabelResultComparator());
    for (String category : categories) {
      double prob = documentWeight(datastore, category, document);
      if (prob > 0.0) {
        pq.add(new ClassifierResult(category, prob));
        if (pq.size() > numResults) {
          pq.remove();
        }
      }
    }
   
    if (pq.isEmpty()) {
      return new ClassifierResult[] {new ClassifierResult(defaultCategory, 0.0)};
    } else {
      List<ClassifierResult> result = new ArrayList<ClassifierResult>(pq.size());
      while (!pq.isEmpty()) {
        result.add(pq.remove());
      }
View Full Code Here

        ofile.writeChar('\n');
      }

      if (analyzer != null) {
        analyzer.addInstance(dataset.getLabel(instance.getLabel()),
                             new ClassifierResult(dataset.getLabel(prediction), 1.0));
      }
    }

    scanner.close();
    input.close();
View Full Code Here

            ofile.writeChars(value); // write the prediction
            ofile.writeChar('\n');

            if (analyzer != null) {
              analyzer.addInstance(dataset.getLabel(key),
                                   new ClassifierResult(dataset.getLabel(Integer.parseInt(value)), 1.0));
            }
          }
        }
      } finally {
        ofile.close();
View Full Code Here

   
    for (String[] entry : ClassifierData.DATA) {
      List<String> document = new NGrams(entry[1], params.getGramSize()).generateNGramsWithoutLabel();
      assertEquals(3, classifier.classifyDocument(document.toArray(new String[document.size()]),
        params.get("defaultCat"), 100).length);
      ClassifierResult result = classifier.classifyDocument(document.toArray(new String[document.size()]), params
          .get("defaultCat"));
      assertEquals(entry[0], result.getLabel());
      resultAnalyzer.addInstance(entry[0], result);
    }
    int[][] matrix = resultAnalyzer.getConfusionMatrix().getConfusionMatrix();
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
View Full Code Here

    ResultAnalyzer resultAnalyzer = new ResultAnalyzer(classifier.getLabels(), params.get("defaultCat"));
    for (String[] entry : ClassifierData.DATA) {
      List<String> document = new NGrams(entry[1], params.getGramSize()).generateNGramsWithoutLabel();
      assertEquals(3, classifier.classifyDocument(document.toArray(new String[document.size()]),
        params.get("defaultCat"), 100).length);
      ClassifierResult result = classifier.classifyDocument(document.toArray(new String[document.size()]), params
          .get("defaultCat"));
      assertEquals(entry[0], result.getLabel());
      resultAnalyzer.addInstance(entry[0], result);
    }
    int[][] matrix = resultAnalyzer.getConfusionMatrix().getConfusionMatrix();
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
View Full Code Here

  @Test
  public void test() throws Exception {
    ClassifierContext classifier = new ClassifierContext(algorithm, store);
    String[] document = {"aa", "ff"};
    ClassifierResult result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
    assertEquals(result + " is not equal to e", "e", result.getLabel());
   
    document = new String[] {"dd"};
    result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
    assertEquals(result + " is not equal to d", "d", result.getLabel());
   
    document = new String[] {"cc"};
    result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
    assertEquals(result + " is not equal to d", "d", result.getLabel());
  }
View Full Code Here

  @Test
  public void testResults() throws Exception {
    ClassifierContext classifier = new ClassifierContext(algorithm, store);
    String[] document = {"aa", "ff"};
    ClassifierResult result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
  }
View Full Code Here

  @Test
  public void test() throws Exception {
    ClassifierContext classifier = new ClassifierContext(algorithm, store);
    String[] document = {"aa", "ff"};
    ClassifierResult result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
    assertEquals(result + " is not equal to e", "e", result.getLabel());
   
    document = new String[] {"dd"};
    result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
    assertEquals(result + " is not equal to d", "d", result.getLabel());
   
    document = new String[] {"cc"};
    result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
    assertEquals(result + " is not equal to d", "d", result.getLabel());
  }
View Full Code Here

  @Test
  public void testResults() throws Exception {
    ClassifierContext classifier = new ClassifierContext(algorithm, store);
    String[] document = {"aa", "ff"};
    ClassifierResult result = classifier.classifyDocument(document, "unknown");
    assertNotNull("category is null and it shouldn't be", result);
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.classifier.ClassifierResult

Copyright © 2018 www.massapicom. 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.