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

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

Introduction

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

Prototype

@Override
    public int run(String[] args) throws Exception 

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);/*  ww  w .  j  a  va 2s .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());
}