List of usage examples for org.apache.mahout.classifier.naivebayes.training TrainNaiveBayesJob setConf
@Override public void setConf(Configuration conf)
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); 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()); }