当前位置: 首页>>代码示例>>Java>>正文


Java ComplementaryNaiveBayesClassifier类代码示例

本文整理汇总了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;
	}
 
开发者ID:T-abide,项目名称:sentiment-analysis-movie-review,代码行数:26,代码来源:NavieBays.java

示例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);
	}
 
开发者ID:T-abide,项目名称:sentiment-analysis-movie-review,代码行数:30,代码来源:NavieBays.java


注:本文中的org.apache.mahout.classifier.naivebayes.ComplementaryNaiveBayesClassifier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。