本文整理汇总了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();
}