Examples of BayesParameters


Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

    }
  }

  @Test
  public void testSelfTestCBayes() throws Exception {
    BayesParameters params = new BayesParameters(1);
    params.set("alpha_i", "1.0");
    params.set("dataSource", "hdfs");
    Path bayesInputPath = getTestTempFilePath("bayesinput");
    Path bayesModelPath = getTestTempDirPath("cbayesmodel");
    TrainClassifier.trainCNaiveBayes(bayesInputPath, bayesModelPath, params);
   
    params.set("verbose", "true");
    params.set("basePath", bayesModelPath.toString());
    params.set("classifierType", "cbayes");
    params.set("dataSource", "hdfs");
    params.set("defaultCat", "unknown");
    params.set("encoding", "UTF-8");
    params.set("alpha_i", "1.0");
   
    Algorithm algorithm = new CBayesAlgorithm();
    Datastore datastore = new InMemoryBayesDatastore(params);
    ClassifierContext classifier = new ClassifierContext(algorithm, datastore);
    classifier.initialize();
    ResultAnalyzer resultAnalyzer = new ResultAnalyzer(classifier.getLabels(), params.get("defaultCat"));
    for (String[] entry : ClassifierData.DATA) {
      List<String> document = new NGrams(entry[1], Integer.parseInt(params.get("gramSize")))
          .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++) {
        assertEquals(i == j ? 4 : 0, matrix[i][j]);
      }
    }
    params.set("testDirPath", bayesInputPath.toString());
    TestClassifier.classifyParallel(params);
    Configuration conf = new Configuration();
    Path outputFiles = getTestTempFilePath("bayesinput-output/part*");
    FileSystem fs = FileSystem.get(outputFiles.toUri(), conf);
    matrix = BayesClassifierDriver.readResult(fs, outputFiles, conf, params).getConfusionMatrix();
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

    return reducerOutput;
  }

  @Test
  public void testNoFilters() throws Exception {
    BayesParameters bp = new BayesParameters();
    bp.setGramSize(1);
    bp.setMinDF(1);
    DummyOutputCollector<StringTuple,DoubleWritable> reduceOutput = runMapReduce(bp);

    assertCounts(reduceOutput,
        17, /* df: 13 unique term/label pairs */
        14, /* fc: 12 unique features across all labels */
 
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

        17  /* wt: 13 unique term/label pairs */);
  }

  @Test
  public void testMinSupport() throws Exception {
    BayesParameters bp = new BayesParameters();
    bp.setGramSize(1);
    bp.setMinSupport(2);
    DummyOutputCollector<StringTuple,DoubleWritable> reduceOutput = runMapReduce(bp);
   
    assertCounts(reduceOutput,
        5, /* df: 5 unique term/label pairs */
        2, /* fc: 'big' and 'cool' appears more than 2 times */
 
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

   
  }

  @Test
  public void testMinDf() throws Exception {
    BayesParameters bp = new BayesParameters();
    bp.setGramSize(1);
    bp.setMinDF(2);
    DummyOutputCollector<StringTuple,DoubleWritable> reduceOutput = runMapReduce(bp);
   
    // 13 unique term/label pairs. 3 labels
    // should be a df and fc for each pair, no filtering
    assertCounts(reduceOutput,
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

   
  }

  @Test
  public void testMinBoth() throws Exception {
    BayesParameters bp = new BayesParameters();
    bp.setGramSize(1);
    bp.setMinSupport(3);
    bp.setMinDF(2);
    DummyOutputCollector<StringTuple,DoubleWritable> reduceOutput = runMapReduce(bp);
   
    // 13 unique term/label pairs. 3 labels
    // should be a df and fc for each pair, no filtering
    assertCounts(reduceOutput,
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

      }
     
      String classifierType = (String) cmdLine.getValue(typeOpt);
      String dataSourceType = (String) cmdLine.getValue(dataSourceOpt);
     
      BayesParameters params = new BayesParameters();
      // Setting all the default parameter values
      params.setGramSize(1);
      params.setMinDF(1);
      params.set("alpha_i","1.0");
      params.set("dataSource", "hdfs");
     
      if (cmdLine.hasOption(gramSizeOpt)) {
        params.setGramSize(Integer.parseInt((String) cmdLine.getValue(gramSizeOpt)));
      }
     
      if (cmdLine.hasOption(minDfOpt)) {
        params.setMinDF(Integer.parseInt((String) cmdLine.getValue(minDfOpt)));
      }
     
      if (cmdLine.hasOption(minSupportOpt)) {
        params.setMinSupport(Integer.parseInt((String) cmdLine.getValue(minSupportOpt)));
      }
     
      if (cmdLine.hasOption(skipCleanupOpt)) {
        params.setSkipCleanup(true);
      }
     
      if (cmdLine.hasOption(alphaOpt)) {
        params.set("alpha_i",(String) cmdLine.getValue(alphaOpt));
      }
     
      if (cmdLine.hasOption(dataSourceOpt)) {
        params.set("dataSource", dataSourceType);
      }

      Path inputPath = new Path((String) cmdLine.getValue(inputDirOpt));
      Path outputPath = new Path((String) cmdLine.getValue(outputOpt));
      if ("cbayes".equalsIgnoreCase(classifierType)) {
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

    if (cmdLine.hasOption(gramSizeOpt)) {
      gramSize = Integer.parseInt((String) cmdLine.getValue(gramSizeOpt));
     
    }
   
    BayesParameters params = new BayesParameters(gramSize);
   
    String modelBasePath = (String) cmdLine.getValue(pathOpt);
   
    log.info("Loading model from: {}", params.print());
   
    Algorithm algorithm;
    Datastore datastore;
   
    String classifierType = (String) cmdLine.getValue(typeOpt);
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    algorithm = new BayesAlgorithm();
    store = new InMemoryBayesDatastore(new BayesParameters(1));
    // String[] labels = new String[]{"a", "b", "c", "d", "e"};
    // long[] labelCounts = new long[]{6, 20, 60, 100, 200};
    // String[] features = new String[]{"aa", "bb", "cc", "dd", "ee"};
    store.setSigmaJSigmaK(100.0);
   
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    algorithm = new CBayesAlgorithm();
    store = new InMemoryBayesDatastore(new BayesParameters(1));
    // String[] labels = new String[]{"a", "b", "c", "d", "e"};
    // long[] labelCounts = new long[]{6, 20, 60, 100, 200};
    // String[] features = new String[]{"aa", "bb", "cc", "dd", "ee"};
    store.setSigmaJSigmaK(500.0);
   
View Full Code Here

Examples of org.apache.mahout.classifier.bayes.common.BayesParameters

    BayesFeatureMapper mapper = new BayesFeatureMapper();
    JobConf conf = new JobConf();
    conf.set("io.serializations",
      "org.apache.hadoop.io.serializer.JavaSerialization,"
          + "org.apache.hadoop.io.serializer.WritableSerialization");
    conf.set("bayes.parameters", new BayesParameters(3).toString());
    mapper.configure(conf);
   
    DummyOutputCollector<StringTuple,DoubleWritable> output = new DummyOutputCollector<StringTuple,DoubleWritable>();
    mapper.map(new Text("foo"), new Text("big brown shoe"), output,
      Reporter.NULL);
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.