當前位置: 首頁>>代碼示例>>Java>>正文


Java Classifier.distributionForInstance方法代碼示例

本文整理匯總了Java中weka.classifiers.Classifier.distributionForInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Classifier.distributionForInstance方法的具體用法?Java Classifier.distributionForInstance怎麽用?Java Classifier.distributionForInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.classifiers.Classifier的用法示例。


在下文中一共展示了Classifier.distributionForInstance方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPrediction

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Generate a single prediction for a test instance given the pre-trained
 * classifier.
 * 
 * @param classifier the pre-trained Classifier to evaluate
 * @param test the test instance
 * @exception Exception if an error occurs
 */
public Prediction getPrediction(Classifier classifier, Instance test)
  throws Exception {

  double actual = test.classValue();
  double[] dist = classifier.distributionForInstance(test);
  if (test.classAttribute().isNominal()) {
    return new NominalPrediction(actual, dist, test.weight());
  } else {
    return new NumericPrediction(actual, dist[0], test.weight());
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:20,代碼來源:EvaluationUtils.java

示例2: processCollection

import weka.classifiers.Classifier; //導入方法依賴的package包/類
@Override
public void processCollection() {

	String topic = this.parent.getTargetLocation().substring(this.parent.getTargetLocation().lastIndexOf("/") + 1);

	// get extracted concepts and propositions
	Extractor ex = this.parent.getPrevExtractor(this);
	this.concepts = ex.getConcepts();
	this.propositions = ex.getPropositions();
	for (Concept c : this.concepts)
		this.fixLemmas(c);

	// group by same label
	Map<Concept, ConceptGroup> groups = LemmaGrouper.group(this.concepts);
	List<Concept> repConcepts = new ArrayList<Concept>(groups.keySet());
	this.parent.log(this, "unique concepts: " + groups.size());

	// build all pairs for classifier
	List<CPair> pairs = this.buildPairs(repConcepts);
	this.parent.log(this, "concept pairs: " + pairs.size());

	// compute similarity features
	Instances features = this.computeFeatures(pairs, topic);

	// apply classifier
	ObjectDoubleMap<CPair> predictions = new ObjectDoubleHashMap<CPair>(pairs.size());
	try {
		Classifier clf = (Classifier) SerializationHelper.read(modelName);
		for (int i = 0; i < pairs.size(); i++) {
			CPair pair = pairs.get(i);
			Instance feat = features.instance(i);
			double[] pred = clf.distributionForInstance(feat);
			predictions.put(pair, pred[1]);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}

	// clustering
	Set<List<Concept>> clusters = clusterer.createClusters(new HashSet<Concept>(repConcepts), predictions);

	// create final cluster and update relations
	this.updateDataStructures(clusters, groups);
	this.clusters = clusters;

	this.parent.log(this, "grouped concepts: " + concepts.size());
	this.parent.log(this, "relations: " + propositions.size());
}
 
開發者ID:UKPLab,項目名稱:ijcnlp2017-cmaps,代碼行數:49,代碼來源:ConceptGrouperSimLog.java

示例3: classifyMessage

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public static double[] classifyMessage(Classifier classifier, Instances trainingData,String message) throws Exception {
         
       

         Instances testset = trainingData.stringFreeStructure();

         // Make message into test instance.
         Instance instance = makeInstance(message, testset);

//         // Filter instance.
//         m_Filter.input(instance);
//         Instance filteredInstance = m_Filter.output();

         // Get index of predicted class value.
         Instance filteredInstance = instance;
         double predicted = classifier.classifyInstance(filteredInstance);

         // Output class value.
         System.err.println("Message classified as : " +
     		       trainingData.classAttribute().value((int)predicted));

         return classifier.distributionForInstance(filteredInstance);

     }
 
開發者ID:SOBotics,項目名稱:SOCVFinder,代碼行數:25,代碼來源:TestWekaClassifier.java

示例4: classifyMessageNaiveBayes

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public double[] classifyMessageNaiveBayes(Classifier classifier, Instances trainingData, Instances instance) throws Exception {

		double predicted = classifier.classifyInstance(instance.get(0));

		double outcomes[] = classifier.distributionForInstance(instance.get(0));
		// Output class value.
		System.out.println("NaivieBayes classified as: " + trainingData.classAttribute().value((int) predicted) + " Threshold: bad=" + outcomes[1] + ", good="
				+ outcomes[0]);

		return outcomes;

	}
 
開發者ID:SOBotics,項目名稱:SOCVFinder,代碼行數:13,代碼來源:CommentHeatCategory.java

示例5: classifyMessageSGD

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public double[] classifyMessageSGD(Classifier classifier, Instances trainingData, Instances instance) throws Exception {

		double predicted = classifier.classifyInstance(instance.get(0));

		double outcomes[] = classifier.distributionForInstance(instance.get(0));
		// Output class value.
		System.out.println(
				"SGD classified as: " + trainingData.classAttribute().value((int) predicted) + " Threshold: bad=" + outcomes[1] + ", good=" + outcomes[0]);

		return outcomes;

	}
 
開發者ID:SOBotics,項目名稱:SOCVFinder,代碼行數:13,代碼來源:CommentHeatCategory.java

示例6: classifyMessageWithFilter

import weka.classifiers.Classifier; //導入方法依賴的package包/類
public double[] classifyMessageWithFilter(Classifier classifier, Instances trainingData, Filter filter, Instances instance) throws Exception {

		Instances instanceFiltered = Filter.useFilter(instance, filter);
		instanceFiltered.setClassIndex(0);

		double predicted = classifier.classifyInstance(instanceFiltered.get(0));

		double outcomes[] = classifier.distributionForInstance(instanceFiltered.get(0));
		// Output class value.
		System.out.println(classifier.getClass().getName() + " classified as: " + trainingData.classAttribute().value((int) predicted) + ": " + predicted
				+ " Threshold: bad=" + outcomes[1] + ", good=" + outcomes[0]);

		return outcomes;

	}
 
開發者ID:SOBotics,項目名稱:SOCVFinder,代碼行數:16,代碼來源:CommentHeatCategory.java

示例7: doPrintClassification

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Store the prediction made by the classifier as a string.
 * 
 * @param classifier the classifier to use
 * @param inst the instance to generate text from
 * @param index the index in the dataset
 * @throws Exception if something goes wrong
 */
@Override
protected void doPrintClassification(Classifier classifier, Instance inst,
  int index) throws Exception {

  double[] d = classifier.distributionForInstance(inst);
  doPrintClassification(d, inst, index);
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:16,代碼來源:CSV.java

示例8: doPrintClassification

import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
 * Store the prediction made by the classifier as a string.
 * 
 * @param classifier	the classifier to use
 * @param inst	the instance to generate text from
 * @param index	the index in the dataset
 * @throws Exception	if something goes wrong
 */
protected void doPrintClassification(Classifier classifier, Instance inst, int index) throws Exception {
  
  double[] d = classifier.distributionForInstance(inst);
  doPrintClassification(d, inst, index);    
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:14,代碼來源:XML.java


注:本文中的weka.classifiers.Classifier.distributionForInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。