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

input the input pathname String
output the output pathname String
   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)) {
     .info("Reading features...");
     //Read the features in each document normalized by length of each document
     BayesFeatureDriver feature = new BayesFeatureDriver();
     .info("Calculating Tf-Idf...");
     //Calculate the TfIdf for each word in each label
     BayesTfIdfDriver tfidf = new BayesTfIdfDriver();
     .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
     .info("Calculating the weight Normalisation factor for each class...");
     //Calculate the normalization factor Sigma_W_ij for each complement class.
     Path docCountOutPath = new Path(output + "/trainer-docCount");
     if (dfs.exists(docCountOutPath)) {
     Path termDocCountOutPath = new Path(output + "/trainer-termDocCount");
     if (dfs.exists(termDocCountOutPath)) {
     Path featureCountOutPath = new Path(output + "/trainer-featureCount");
     if (dfs.exists(featureCountOutPath)) {
     Path wordFreqOutPath = new Path(output + "/trainer-wordFreq");
     if (dfs.exists(wordFreqOutPath)) {
     Path vocabCountPath = new Path(output + "/trainer-tfIdf/trainer-vocabCount");
     if (dfs.exists(vocabCountPath)) {
     Path vocabCountOutPath = new Path(output + "/trainer-vocabCount");
     if (dfs.exists(vocabCountOutPath)) {
New to GrepCode? Check out our FAQ X