當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。