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


Java Instance.numClasses方法代碼示例

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


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

示例1: getVotesForInstance

import weka.core.Instance; //導入方法依賴的package包/類
@Override
	public double[] getVotesForInstance(Instance inst) {
		// TODO Auto-generated method stub
		
		// increase no. of seen intances
		totalSeenInstances++;
		
		// check if there is any rules that cover the instance
		ArrayList<Rule> coveredRules = RulesCoveredInstance(inst);
//		logger.debug("No. Rules cover instance: " + coveredRules.size());
		
//		logger.debug(inst);
		// return prediction if there are rules that cover the instance
		if(coveredRules.size() > 0){
			
			actualAttempts++;
			
			double[] classPrediction = new double[inst.numClasses()];
			// vote class labels from all available rules
			
			for (Rule rule : coveredRules) {
				classPrediction[(int)rule.classification]++;
//				logger.debug(rule.printRule());
                        }
                        
			// actual attempt
			if(Utils.maxIndex(classPrediction) == (int) inst.classValue()){
				actualAttemptsCorrectlyClassified++;
			}
			return classPrediction ;
		}
		
		// otherwise, return the majority class
		return observedClassDistribution.getArrayCopy();
	}
 
開發者ID:thienle2401,項目名稱:G-eRules,代碼行數:36,代碼來源:GeRules.java

示例2: initialiseGaussianDistributionForNumericAttribute

import weka.core.Instance; //導入方法依賴的package包/類
private Map<Attribute, Map<Double, NormalDistribution>> initialiseGaussianDistributionForNumericAttribute(Instance instanceInfo, ArrayList<Instance> instancesList){
	
	Map<Attribute, Map<Double, NormalDistribution>> numericAttributeClassGaussDistributions = new HashMap<>();
	
	// go through each numeric attibute
	for (Attribute attribute : Collections.list(instanceInfo.enumerateAttributes())) {
		
		// check whether the attribute is numeric
		if(attribute.isNumeric()){
			
			// for each class label
			HashMap<Double, NormalDistribution> classLabelDistribution = new HashMap<>();
			for (int classLabelNo = 0; classLabelNo < instanceInfo.numClasses(); classLabelNo++) {
				
				// go through all instance in the dataset to create normal distribution
				SummaryStatistics summaryStatistics = new SummaryStatistics();
				for (Instance instance : instancesList) {
					
					summaryStatistics.addValue(instance.value(attribute));
				}
				
				// create normal distribution for this attribute with corresponding
				// class label
				NormalDistribution normalDistribution = new NormalDistribution(
						summaryStatistics.getMean(), 
						summaryStatistics.getStandardDeviation());
				
				// map to hold classLabel and distribution
				classLabelDistribution.put((double) classLabelNo, normalDistribution);
				
			}
			
			// put it into the map
			numericAttributeClassGaussDistributions.put(attribute, classLabelDistribution);
		}
		
	}
				
	return numericAttributeClassGaussDistributions;
}
 
開發者ID:thienle2401,項目名稱:G-eRules,代碼行數:41,代碼來源:GeRules.java


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