本文整理汇总了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();
}
示例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;
}