本文整理匯總了Java中org.apache.mahout.classifier.naivebayes.ComplementaryNaiveBayesClassifier類的典型用法代碼示例。如果您正苦於以下問題:Java ComplementaryNaiveBayesClassifier類的具體用法?Java ComplementaryNaiveBayesClassifier怎麽用?Java ComplementaryNaiveBayesClassifier使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ComplementaryNaiveBayesClassifier類屬於org.apache.mahout.classifier.naivebayes包,在下文中一共展示了ComplementaryNaiveBayesClassifier類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: predict
import org.apache.mahout.classifier.naivebayes.ComplementaryNaiveBayesClassifier; //導入依賴的package包/類
public Vector predict(Vector vector) throws URISyntaxException {
Vector prediction = null;
try {
Configuration conf = new Configuration();
// String outputDirectory = "src/main/resources/data/model/NavieBays_" + ModelConfig.FeatureNumber + "/";
NaiveBayesModel naiveBayesModel = NaiveBayesModel.materialize(new Path(
new DirSwitch().NavieBays_predict(ModelConfig.FeatureNumber)), conf);
this.classifier = new ComplementaryNaiveBayesClassifier(naiveBayesModel);
prediction = classifier.classifyFull(vector);
double sum = 0;
for (int i = 0; i < 4; i++) {
sum += prediction.get(i);
}
prediction.set(0, prediction.get(0)/sum);
prediction.set(1, prediction.get(1)/sum);
prediction.set(2, prediction.get(2)/sum);
prediction.set(3, prediction.get(3)/sum);
} catch (IOException e) {
e.printStackTrace();
}
return prediction;
}
示例2: train
import org.apache.mahout.classifier.naivebayes.ComplementaryNaiveBayesClassifier; //導入依賴的package包/類
public void train() throws Throwable {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf);
TrainNaiveBayesJob trainNaiveBayes = new TrainNaiveBayesJob();
trainNaiveBayes.setConf(conf);
String sequenceFile = "src/main/resources/data/NavieBays/seq";
// String outputDirectory = "data/NavieBays/output";
String outputDirectory = "src/main/resources/data/model/NavieBays_" + ModelConfig.FeatureNumber + "/";
String tempDirectory = "src/main/resources/data/NavieBays/temp";
fs.delete(new Path(outputDirectory), true);
fs.delete(new Path(tempDirectory), true);
trainNaiveBayes.run(new String[] { "--input", sequenceFile, "--output",
outputDirectory, "-el", "--overwrite", "--tempDir",
tempDirectory });
// Train the classifier
NaiveBayesModel naiveBayesModel = NaiveBayesModel.materialize(new Path(
outputDirectory), conf);
System.out.println("features: " + naiveBayesModel.numFeatures());
System.out.println("labels: " + naiveBayesModel.numLabels());
this.classifier = new ComplementaryNaiveBayesClassifier(naiveBayesModel);
}