Example usage for org.apache.mahout.classifier.naivebayes.training TrainNaiveBayesJob TrainNaiveBayesJob

List of usage examples for org.apache.mahout.classifier.naivebayes.training TrainNaiveBayesJob TrainNaiveBayesJob

Introduction

In this page you can find the example usage for org.apache.mahout.classifier.naivebayes.training TrainNaiveBayesJob TrainNaiveBayesJob.

Prototype

TrainNaiveBayesJob

Source Link

Usage

From source file:hk.newsRecommender.Classify.java

License:Open Source License

public static void train(Configuration conf, String trainSeqFile, String outputPath) throws Exception {
    System.out.println("~~~ begin to train ~~~");
    String outputDirectory = outputPath + "/result";
    String tempDirectory = outputPath + "/temp";
    FileSystem fs = FileSystem.get(conf);
    TrainNaiveBayesJob trainNaiveBayes = new TrainNaiveBayesJob();
    trainNaiveBayes.setConf(conf);//from   w  w w  .  ja  va  2 s  . c o m

    fs.delete(new Path(outputDirectory), true);
    fs.delete(new Path(tempDirectory), true);
    // cmd sample: mahout trainnb -i train-vectors -el -li labelindex -o model -ow -c
    trainNaiveBayes.run(new String[] { "--input", trainSeqFile, "--output", outputDirectory, "-el",
            "--labelIndex", "labelIndex", "--overwrite", "--tempDir", tempDirectory });

    // Train the classifier
    naiveBayesModel = NaiveBayesModel.materialize(new Path(outputDirectory), conf);

    System.out.println("features: " + naiveBayesModel.numFeatures());
    System.out.println("labels: " + naiveBayesModel.numLabels());
}