當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。