當前位置: 首頁>>代碼示例>>Java>>正文


Java Attribute.index方法代碼示例

本文整理匯總了Java中weka.core.Attribute.index方法的典型用法代碼示例。如果您正苦於以下問題:Java Attribute.index方法的具體用法?Java Attribute.index怎麽用?Java Attribute.index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.core.Attribute的用法示例。


在下文中一共展示了Attribute.index方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: instanceToDenseDMatrix

import weka.core.Attribute; //導入方法依賴的package包/類
public static DMatrix instanceToDenseDMatrix(Instance instance) throws XGBoostError {
    Attribute classAttribute = instance.classAttribute();
    int classAttrIndex = classAttribute.index();

    int colNum = instance.numAttributes()-1;
    int rowNum = 1;

    float[] data = new float[colNum*rowNum];

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

    return new DMatrix(data, rowNum, colNum);
}
 
開發者ID:SigDelta,項目名稱:weka-xgboost,代碼行數:24,代碼來源:DMatrixLoader.java

示例2: instancesToDenseDMatrix

import weka.core.Attribute; //導入方法依賴的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

示例3: processInstance

import weka.core.Attribute; //導入方法依賴的package包/類
protected static void processInstance(Instance instance, List<Float> dataList, List<Integer> colList ){
        Attribute classAttribute = instance.classAttribute();
        int classAttrIndex = classAttribute.index();
        Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
        while (attributeEnumeration.hasMoreElements()) {
            Attribute attribute = attributeEnumeration.nextElement();
//            System.out.print(attribute.name()+", ");
            int attrIndex = attribute.index();

            if(attrIndex == classAttrIndex){
                continue;
            }
            double value = instance.value(attribute);

            if (value == 0) {
                continue;
            }

            dataList.add((float) value);

            if (attrIndex < classAttrIndex) {
                colList.add(attrIndex);
            }else{
                colList.add(attrIndex+1);
            }

        }
//        System.out.println();
    }
 
開發者ID:SigDelta,項目名稱:weka-xgboost,代碼行數:30,代碼來源:DMatrixLoader.java


注:本文中的weka.core.Attribute.index方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。