Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.mahout.classifier.bayes.mapreduce.bayes;
 
 import  org.apache.hadoop.fs.FileSystem;
 import  org.apache.hadoop.fs.Path;
 import  org.apache.hadoop.mapred.JobConf;
 
Create and run the Bayes Trainer.
 
 public class BayesDriver implements BayesJob {
 
   private static final Logger log = LoggerFactory.getLogger(BayesDriver.class);

  
Run the job

Parameters:
input the input pathname String
output the output pathname String
Throws:
ClassNotFoundException
InterruptedException
 
   @Override
   public void runJob(String inputString outputBayesParameters paramsthrows IOExceptionInterruptedExceptionClassNotFoundException {
     JobConf conf = new JobConf(BayesDriver.class);
     Path outPath = new Path(output);
     FileSystem dfs = FileSystem.get(outPath.toUri(), conf);
     if (dfs.exists(outPath)) {
       dfs.delete(outPathtrue);
     }
 
     .info("Reading features...");
     //Read the features in each document normalized by length of each document
     BayesFeatureDriver feature = new BayesFeatureDriver();
     feature.runJob(inputoutputparams);
 
     .info("Calculating Tf-Idf...");
     //Calculate the TfIdf for each word in each label
     BayesTfIdfDriver tfidf = new BayesTfIdfDriver();
     tfidf.runJob(inputoutputparams);
 
     .info("Calculating weight sums for labels and features...");
     //Calculate the Sums of weights for each label, for each feature and for each feature and for each label
     summer.runJob(inputoutputparams);
 
     .info("Calculating the weight Normalisation factor for each class...");
     //Calculate the normalization factor Sigma_W_ij for each complement class.
     normalizer.runJob(inputoutputparams);
 
     Path docCountOutPath = new Path(output + "/trainer-docCount");
     if (dfs.exists(docCountOutPath)) {
       dfs.delete(docCountOutPathtrue);
     }
     Path termDocCountOutPath = new Path(output + "/trainer-termDocCount");
     if (dfs.exists(termDocCountOutPath)) {
       dfs.delete(termDocCountOutPathtrue);
     }
     Path featureCountOutPath = new Path(output + "/trainer-featureCount");
     if (dfs.exists(featureCountOutPath)) {
       dfs.delete(featureCountOutPathtrue);
     }
     Path wordFreqOutPath = new Path(output + "/trainer-wordFreq");
     if (dfs.exists(wordFreqOutPath)) {
       dfs.delete(wordFreqOutPathtrue);
     }
     Path vocabCountPath = new Path(output + "/trainer-tfIdf/trainer-vocabCount");
     if (dfs.exists(vocabCountPath)) {
       dfs.delete(vocabCountPathtrue);
     }
     Path vocabCountOutPath = new Path(output + "/trainer-vocabCount");
     if (dfs.exists(vocabCountOutPath)) {
       dfs.delete(vocabCountOutPathtrue);
     }
 
  }
New to GrepCode? Check out our FAQ X