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


Java Instances.size方法代码示例

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


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

示例1: buildAssociate

import weka.core.Instances; //导入方法依赖的package包/类
public static String buildAssociate() throws Exception {
    InstanceQuery query = new InstanceQuery();
    query.setUsername("root");
    query.setPassword("cs6310");
    query.setDatabaseURL("jdbc:mysql://localhost/system?#characterEncoding=UTF-8");
    query.setQuery("select * from courses_sessions;");
    // You can declare that your data set is sparse
    // query.setSparseData(true);
    Instances data = query.retrieveInstances();
    data.setClassIndex(data.numAttributes() - 1);

    final NumericToNominal filter = new NumericToNominal();

    filter.setInputFormat(data);
    data = Filter.useFilter(data, filter);
    if (data.size() > 0) {
        // build associator
        Apriori apriori = new Apriori();
        apriori.setClassIndex(data.classIndex());
        apriori.buildAssociations(data);
        return String.valueOf(apriori);
    } else {
        return "Not enough data provided";
    }
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:26,代码来源:WekaDataMiner.java

示例2: instancesToDMatrix

import weka.core.Instances; //导入方法依赖的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

示例3: calculateSupport

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Calculate support value of a given rule on the dataset
 * 
 * @param dataset the dataset
 * @param bodySide left-side or BODY part of the rule
 * @return support value for the rule on the given dataset
 */
public double calculateSupport(Instances dataset, List<Term> bodySide){
    
    Iterator<Instance> datasetIterator = dataset.iterator();
    int supportCount = 0;
    
    while(datasetIterator.hasNext()){
        
        Instance anInstance = datasetIterator.next();
        
        if(instanceCoveredByTermsList(anInstance,bodySide)){
            supportCount++;
        }
        
    }
    return !dataset.isEmpty() ? (double) supportCount / (double) dataset.size() : 0.0d;
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:24,代码来源:GRules.java

示例4: calcualteRuleJMeasure

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Calculate J-measure of the dataset for given body/ left and head/ right
 * 
 * @param datasetIn
 * @param bodyPart
 * @param headPart
 * @return 
 */
public double calcualteRuleJMeasure(Instances datasetIn, List<Term> bodyPart, List<Term> headPart){
    
    int bodyCoveredCount = 0;
    int headCoveredCount = 0;
    int bothBodyHeadCovered = 0;
    
    for (int i = 0; i < datasetIn.size(); i++) {
        
        // check if the instance is covered by body/ left side
        if(instanceCoveredByTermsList(datasetIn.get(i), bodyPart) == true){
            bodyCoveredCount++;
            
            // check whether the instance is also covered by head/ right
            if(instanceCoveredByTermsList(datasetIn.get(i), headPart) == true){
                bothBodyHeadCovered++;
            }
        }
        
        // if the instance is not covered by body/ left, then check if
        // the instance is covered only head/ right
        if(instanceCoveredByTermsList(datasetIn.get(i), headPart) == true){
            headCoveredCount++;
        }
    }
    
    // calcate required probabilities 
    double xyConditionalProbability = (double) bothBodyHeadCovered / bodyCoveredCount;
    double headProbability = (double) headCoveredCount / datasetIn.size();
    double bodyProbability = (double) bodyCoveredCount / datasetIn.size();
    
    double JMeasureValue = calculateJMeasure(xyConditionalProbability, headProbability, bodyProbability);
    
    return JMeasureValue;
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:43,代码来源:GRules.java

示例5: instancesToDenseDMatrix

import weka.core.Instances; //导入方法依赖的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: calcualteWRA

import weka.core.Instances; //导入方法依赖的package包/类
/**
 * Calculate Weighted Relative Accuracy (WRA) for from the input dataset for a given rule.
 * 
 * @param dataset the dataset
 * @param aLeftHandSide left-side (BODY) of the rule
 * @param aRightHandSide right-side (HEAD) of the rule
 * @return WRA value of the rule on the dataset
 */
public double calcualteWRA(Instances dataset, List<Term> aLeftHandSide, List<Term> aRightHandSide){
    
    double totalPositive;
    double totalNegative;
    
    double ruleTruePositive = 0;
    double ruleFalsePositive = 0;
    
    double ruleTrueNegative = 0;
    double ruleFalseNegative = 0;
    
    
    // calcualte truePositive, trueNegative, falsePostive, falseNegative for the Rules
    for (int instanceI = 0; instanceI < dataset.size(); instanceI++) {
        
        Instance anInstance = dataset.get(instanceI);
        
        // calculate true postive and true negative instances for the rules
        if(instanceCoveredByTermsList(anInstance, aLeftHandSide)){
            
            if(instanceCoveredByTermsList(anInstance, aRightHandSide)){
                ruleTruePositive++;
            }else{
                ruleFalsePositive++;
            }
        }else if(instanceCoveredByTermsList(anInstance, aRightHandSide)){
            ruleFalsePositive++;
        }else{
            ruleTrueNegative++;
        }
    }
    
    // calculate totalPositive and totalNegative
    totalPositive = ruleTruePositive + ruleFalseNegative;
    totalNegative = ruleFalsePositive + ruleTrueNegative;
    
    // start calcualting WRA      
    double ruleWRA = (ruleTruePositive + ruleFalsePositive) / (totalPositive + totalNegative) * 
            (  (ruleTruePositive / (ruleTruePositive + ruleFalsePositive) - ( totalPositive / (totalPositive + totalNegative) )));
    
    return ruleWRA; 
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:51,代码来源:GRules.java

示例7: runJ48

import weka.core.Instances; //导入方法依赖的package包/类
public static void runJ48(Instances instances) {
    int split = (int) (instances.size() * 0.7);
    Instances trainSet = new Instances(instances, 0, split);
    Instances testSet = new Instances(instances, split, instances.size() - split);
    runJ48(trainSet, testSet);
}
 
开发者ID:GeorgiMateev,项目名称:twitter-user-gender-classification,代码行数:7,代码来源:Classification.java

示例8: runNaiveBayes

import weka.core.Instances; //导入方法依赖的package包/类
public static void runNaiveBayes(Instances instances) {
    int split = (int) (instances.size() * 0.7);
    Instances trainSet = new Instances(instances, 0, split);
    Instances testSet = new Instances(instances, split, instances.size() - split);
    runNaiveBayes(trainSet, testSet);
}
 
开发者ID:GeorgiMateev,项目名称:twitter-user-gender-classification,代码行数:7,代码来源:Classification.java

示例9: runSMO

import weka.core.Instances; //导入方法依赖的package包/类
public static void runSMO(Instances instances) {
    int split = (int) (instances.size() * 0.7);
    Instances trainSet = new Instances(instances, 0, split);
    Instances testSet = new Instances(instances, split, instances.size() - split);
    runSMO(trainSet, testSet);
}
 
开发者ID:GeorgiMateev,项目名称:twitter-user-gender-classification,代码行数:7,代码来源:Classification.java

示例10: runIBk

import weka.core.Instances; //导入方法依赖的package包/类
public static void runIBk(Instances instances) {
    int split = (int) (instances.size() * 0.7);
    Instances trainSet = new Instances(instances, 0, split);
    Instances testSet = new Instances(instances, split, instances.size() - split);
    runIBk(trainSet, testSet);
}
 
开发者ID:GeorgiMateev,项目名称:twitter-user-gender-classification,代码行数:7,代码来源:Classification.java


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