当前位置: 首页>>代码示例>>Java>>正文


Java Instance.classValue方法代码示例

本文整理汇总了Java中weka.core.Instance.classValue方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.classValue方法的具体用法?Java Instance.classValue怎么用?Java Instance.classValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.Instance的用法示例。


在下文中一共展示了Instance.classValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: instancesToDMatrix

import weka.core.Instance; //导入方法依赖的package包/类
public static DMatrix instancesToDMatrix(Instances instances) throws XGBoostError {
    long[] rowHeaders = new long[instances.size()+1];
    rowHeaders[0]=0;
    List<Float> dataList = new ArrayList<>();
    List<Integer> colList = new ArrayList<>();
    float[] labels = new float[instances.size()];

    for(int i=0; i<instances.size(); i++) {
        Instance instance = instances.get(i);
        rowHeaders[i] = dataList.size();
        processInstance(instance, dataList, colList);
        labels[i] = (float) instance.classValue();
    }
    rowHeaders[rowHeaders.length - 1] = dataList.size();
    int colNum = instances.numAttributes()-1;
    DMatrix dMatrix = createDMatrix(rowHeaders, dataList, colList, colNum);

    dMatrix.setLabel(labels);
    return dMatrix;

}
 
开发者ID:SigDelta,项目名称:weka-xgboost,代码行数:22,代码来源:DMatrixLoader.java

示例2: isClassTheMajortiy

import weka.core.Instance; //导入方法依赖的package包/类
private boolean isClassTheMajortiy(ArrayList<Instance> instances, double classification){
	
	List<Instance> instancesList = new ArrayList<>(instances);
	TreeMap<Double, Double> classificationProbability = new TreeMap<>();
	Attribute classAttribute = instances.get(0).classAttribute();
	
	for (double i = 0; i < classAttribute.numValues(); i++) {
		int matchedClassCount = 0;
		
		for (Instance instance : instancesList) {
			if(instance.classValue() == i){
				matchedClassCount++;
			}
		}
		
		classificationProbability.put(((double) matchedClassCount / (double) instancesList.size()), i);
	}
	
	return (classificationProbability.lastEntry().getValue() == classification);
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:21,代码来源:GeRules.java

示例3: 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

示例4: containOtherClasses

import weka.core.Instance; //导入方法依赖的package包/类
private boolean containOtherClasses(ArrayList<Instance> instances, double classification){
	
	List<Instance> instancesList = new ArrayList<>(instances);
	
	for (Instance instance : instancesList) {
		if(instance.classValue() != classification){
			return false;
		}
	}
	return true;
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:12,代码来源:GeRules.java

示例5: instancesToDenseDMatrix

import weka.core.Instance; //导入方法依赖的package包/类
public static DMatrix instancesToDenseDMatrix(Instances instances) throws XGBoostError {
    int colNum = instances.numAttributes()-1;
    int rowNum = instances.size();

    float[] data = new float[colNum*rowNum];
    float[] labels = new float[instances.size()];
    Attribute classAttribute = instances.classAttribute();
    int classAttrIndex = classAttribute.index();

    for(int i=0, dataIndex = 0; i<instances.size(); i++) {
        Instance instance = instances.get(i);

        labels[i] = (float) instance.classValue();
        Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
        while (attributeEnumeration.hasMoreElements()) {
            Attribute attribute = attributeEnumeration.nextElement();
            int attrIndex = attribute.index();
            if(attrIndex == classAttrIndex){
                continue;
            }
            data[dataIndex]= (float) instance.value(attribute);
            dataIndex++;
        }
    }


    DMatrix dMatrix = new DMatrix(data, rowNum, colNum);

    dMatrix.setLabel(labels);
    return dMatrix;

}
 
开发者ID:SigDelta,项目名称:weka-xgboost,代码行数:33,代码来源:DMatrixLoader.java

示例6: getInstanceWithPossibleMaxY

import weka.core.Instance; //导入方法依赖的package包/类
/**
 * @param samplePoint : some attributes are flexible; for such attributes, we use values of the samplepoint
 * @return
 * @throws Exception 
 */
public Instance getInstanceWithPossibleMaxY(Instance samplePoint) throws Exception{
	Instance retval = null;
	
	//we actually have the model
	if(models!=null){
		ArrayList<Branch2>[] branchLists = new ArrayList[ModelNum];
		for(int m=0;m<ModelNum;m++){
			branchLists[m] = getLeavesInfoForM5P(models[m]);
		}
		
		//now we intersect each leaf
		ArrayList<Branch2> combined = branchLists[0];
		for(int m=1;m<ModelNum;m++){
			combined = intersectBranch2Lists(combined, branchLists[m]);
		}
		
		//now we find the best in the combined list
		Instance temp;
		for(Branch2 branch : combined){
			temp = branch.maxPoint(samplePoint.dataset());
			if(retval==null || retval.classValue()<temp.classValue()){
				retval = temp;
				System.out.println("Current best performance is : "+retval.classValue());
			}
		}
	}
	return retval;
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:34,代码来源:COMT2.java

示例7: trainOnInstanceImpl

import weka.core.Instance; //导入方法依赖的package包/类
@Override
public void trainOnInstanceImpl(Instance inst) {
	// TODO Auto-generated method stub
	
	// add weight of respective class to classification distribution
	observedClassDistribution.addToValue((int) inst.classValue(), inst.weight());
	
	// only add instances to be learnt if there are no rule coverd the instance
	if(RulesCoveredInstance(inst).isEmpty()){
		slidingWindowsBuffer.add(inst);
	}
	// if there are rule(s) cover the instance, then update stattic in the rule
	else{
		
		// for each rule matched the instance,
		// update class distribution statistic
		for (Rule rule : RulesCoveredInstance(inst)) {
			rule.updateClassDistribution(inst);
			
			rule.noOfCovered++;
			
			// also update if the rule correctly cover an instance with it class
			if(inst.classValue() == rule.classification){
				rule.noOfCorrectlyCovered++;
			}else{					// validate the current rule
				if(rule.ruleShouldBeRemoved()){
					rulesList.remove(rule);
				}	
			}	
		}
		
	}
	
	// check if the sliding windows buffer is filled to the criteria
	if(slidingWindowsBuffer.size() == slidingWindowsSizeOption.getValue()){
					
                   // learn rules with the classifier
                   ArrayList<Rule> learntRules = prismClassifier.learnRules(slidingWindowsBuffer);

                   if(learntRules != null){
                           rulesList.addAll(learntRules);
                   }

                   // clear sliding window buffer to take more instances
                   slidingWindowsBuffer.clear();
	}
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:48,代码来源:GeRules.java

示例8: calculateProbabilityOfOccurence

import weka.core.Instance; //导入方法依赖的package包/类
private double calculateProbabilityOfOccurence(RuleTerm ruleTerm, ArrayList<Instance> dataset, double classification ){
	
	int totalNoInstancesCoveredByRuleTerm = 0;
	int totalNoInstancesCoveredByRuleTermWithClassification = 0;
	List<Instance> instancesList = new ArrayList<>(dataset);
	
	for (Instance instance : instancesList) {
                          
		if(instance.value(ruleTerm.attribute) == ruleTerm.value){

			totalNoInstancesCoveredByRuleTerm++;
			
			// check if ruleTerm covered instance for specific classification
			if(instance.classValue() == classification){
				totalNoInstancesCoveredByRuleTermWithClassification++;
			}
			
		}
	}
	
	double probabilityOfOccurencesForClassification = (double) totalNoInstancesCoveredByRuleTermWithClassification / (double) totalNoInstancesCoveredByRuleTerm;
	
	
	return Double.isNaN(probabilityOfOccurencesForClassification) ? 0.0d : probabilityOfOccurencesForClassification;
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:26,代码来源:GeRules.java

示例9: notContainClassification

import weka.core.Instance; //导入方法依赖的package包/类
private boolean notContainClassification(ArrayList<Instance> instances, double classification){
	
	List<Instance> instancesList = new ArrayList<>(instances);
	
	for (Instance instance : instancesList) {
		if(instance.classValue() == classification){
			
			return false;
		}
	}
	
	return true;
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:14,代码来源:GeRules.java

示例10: updateClassDistribution

import weka.core.Instance; //导入方法依赖的package包/类
public void updateClassDistribution(Instance instance){
	
	// update class distribution of the rule with correct class label
	classDistribution[(int) instance.classValue()]++;
	
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:7,代码来源:GeRules.java


注:本文中的weka.core.Instance.classValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。