Package org.apache.mahout.classifier.bayes.common

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


      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

  }
 
  @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

Related Classes of org.apache.mahout.classifier.bayes.common.BayesParameters

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.