当前位置: 首页>>代码示例>>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;未经允许,请勿转载。