本文整理汇总了Java中weka.core.Instance.enumerateAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.enumerateAttributes方法的具体用法?Java Instance.enumerateAttributes怎么用?Java Instance.enumerateAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Instance
的用法示例。
在下文中一共展示了Instance.enumerateAttributes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instanceToDenseDMatrix
import weka.core.Instance; //导入方法依赖的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.Instance; //导入方法依赖的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.Instance; //导入方法依赖的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();
}
示例4: instanceToMap
import weka.core.Instance; //导入方法依赖的package包/类
public static Map<Attribute, Double> instanceToMap(Instance ins){
HashMap<Attribute, Double> retval = new HashMap<Attribute, Double>();
Enumeration<Attribute> enu = ins.enumerateAttributes();
while(enu.hasMoreElements()){
Attribute temp = enu.nextElement();
retval.put(temp, ins.value(temp));
}
return retval;
}