Examples of BayesParameters


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

      }
     
      Path input = new Path(cmdLine.getValue(inputOpt).toString());
      Path output = new Path(cmdLine.getValue(outputOpt).toString());

      BayesParameters bayesParams = new BayesParameters();
      bayesParams.setGramSize(1);
      job.runJob(input, output, bayesParams);
    } catch (OptionException e) {
      log.error(e.getMessage());
      CommandLineUtil.printHelp(group);
    }
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();
    params.setGramSize(gramSize);
    String modelBasePath = (String) cmdLine.getValue(pathOpt);
    params.setBasePath(modelBasePath);

    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 CBayesAlgorithm();
    BayesParameters bayesParams = new BayesParameters();
    bayesParams.setGramSize(1);
    store = new InMemoryBayesDatastore(bayesParams);
    // 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");
    BayesParameters bayesParams = new BayesParameters();
    bayesParams.setGramSize(3);
    conf.set("bayes.parameters", bayesParams.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

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

    fs.copyFromLocalFile(new Path(tempInputFile.getAbsolutePath()), input);
  }

  @Test
  public void testSelfTestBayes() throws Exception {
    BayesParameters params = new BayesParameters();
    params.setGramSize(1);
    params.set("alpha_i", "1.0");
    params.set("dataSource", "hdfs");
    Path bayesInputPath = getTestTempFilePath("bayesinput");
    Path bayesModelPath = getTestTempDirPath("bayesmodel");
    TrainClassifier.trainNaiveBayes(bayesInputPath, bayesModelPath, params);
   
    params.set("verbose", "true");
    params.setBasePath(bayesModelPath.toString());
    params.set("classifierType", "bayes");
    params.set("dataSource", "hdfs");
    params.set("defaultCat", "unknown");
    params.set("encoding", "UTF-8");
    params.set("alpha_i", "1.0");
   
    Algorithm algorithm = new BayesAlgorithm();
    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], 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++) {
        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*");
    matrix = BayesClassifierDriver.readResult(outputFiles, conf, params).getConfusionMatrix();
    for (int i = 0; i < 3; i++) {
View Full Code Here

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

    }
  }

  @Test
  public void testSelfTestCBayes() throws Exception {
    BayesParameters params = new BayesParameters();
    params.setGramSize(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.setBasePath(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], 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++) {
        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*");
    matrix = BayesClassifierDriver.readResult(outputFiles, conf, params).getConfusionMatrix();
    for (int i = 0; i < 3; i++) {
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();
    BayesParameters bayesParams = new BayesParameters();
    bayesParams.setGramSize(1);
    store = new InMemoryBayesDatastore(bayesParams);
    // 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

      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return;
      }
     
      BayesParameters params = new BayesParameters();
      // Setting all default values
      int gramSize = 1;

      String modelBasePath = (String) cmdLine.getValue(pathOpt);
     
      if (cmdLine.hasOption(gramSizeOpt)) {
        gramSize = Integer.parseInt((String) cmdLine.getValue(gramSizeOpt));
       
      }

      String classifierType = "bayes";
      if (cmdLine.hasOption(typeOpt)) {
        classifierType = (String) cmdLine.getValue(typeOpt);
      }

      String dataSource = "hdfs";
      if (cmdLine.hasOption(dataSourceOpt)) {
        dataSource = (String) cmdLine.getValue(dataSourceOpt);
      }

      String defaultCat = "unknown";
      if (cmdLine.hasOption(defaultCatOpt)) {
        defaultCat = (String) cmdLine.getValue(defaultCatOpt);
      }

      String encoding = "UTF-8";
      if (cmdLine.hasOption(encodingOpt)) {
        encoding = (String) cmdLine.getValue(encodingOpt);
      }

      String alphaI = "1.0";
      if (cmdLine.hasOption(alphaOpt)) {
        alphaI = (String) cmdLine.getValue(alphaOpt);
      }
     
      boolean verbose = cmdLine.hasOption(verboseOutputOpt);
     
      String testDirPath = (String) cmdLine.getValue(dirOpt);

      String classificationMethod = "sequential";
      if (cmdLine.hasOption(methodOpt)) {
        classificationMethod = (String) cmdLine.getValue(methodOpt);
      }
     
      params.setGramSize(gramSize);
      params.set("verbose", Boolean.toString(verbose));
      params.setBasePath(modelBasePath);
      params.set("classifierType", classifierType);
      params.set("dataSource", dataSource);
      params.set("defaultCat", defaultCat);
      params.set("encoding", encoding);
      params.set("alpha_i", alphaI);
      params.set("testDirPath", testDirPath);
     
      if ("sequential".equalsIgnoreCase(classificationMethod)) {
        classifySequential(params);
      } else if ("mapreduce".equalsIgnoreCase(classificationMethod)) {
        classifyParallel(params);
View Full Code Here

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

  }
 
  @Override
  public void configure(JobConf job) {
    try {
      BayesParameters params = new BayesParameters(job.get("bayes.parameters", ""));
      log.info("Bayes Parameter {}", params.print());
      log.info("{}", params.print());
      Algorithm algorithm;
      Datastore datastore;
     
      if ("hdfs".equals(params.get("dataSource"))) {
        if ("bayes".equalsIgnoreCase(params.get("classifierType"))) {
          log.info("Testing Bayes Classifier");
          algorithm = new BayesAlgorithm();
          datastore = new InMemoryBayesDatastore(params);
        } else if ("cbayes".equalsIgnoreCase(params.get("classifierType"))) {
          log.info("Testing Complementary Bayes Classifier");
          algorithm = new CBayesAlgorithm();
          datastore = new InMemoryBayesDatastore(params);
        } else {
          throw new IllegalArgumentException("Unrecognized classifier type: " + params.get("classifierType"));
        }
       
      } else {
        throw new IllegalArgumentException("Unrecognized dataSource type: " + params.get("dataSource"));
      }
      classifier = new ClassifierContext(algorithm, datastore);
      classifier.initialize();
     
      defaultCategory = params.get("defaultCat");
      gramSize = params.getGramSize();
    } catch (IOException ex) {
      log.warn(ex.toString(), ex);
    } catch (InvalidDatastoreException e) {
      log.error(e.toString(), e);
    }
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.