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