/** * Weka attribute. * * @param index the index * @param attribute the attribute * @return the weka.core. attribute */ protected weka.core.Attribute wekaAttribute(int index, Attribute attribute) { weka.core.Attribute wekaAttribute; if (attribute.isNominal()) { wekaAttribute = new weka.core.Attribute(attribute.name(), attribute.getAttributeValues(), index); } else { wekaAttribute = new weka.core.Attribute(attribute.name(), index); } //System.out.println(wekaAttribute.name()); //System.out.println(wekaAttribute.isNominal()); return wekaAttribute; } }
public void initHeader(Instances dataset) { int numLabels = this.numOldLabelsOption.getValue(); Attribute target = dataset.classAttribute(); List<String> possibleValues = new ArrayList<String>(); int n = target.numValues(); for (int i = 0; i < n; i++) { possibleValues.add(target.value(i)); } ArrayList<Attribute> attrs = new ArrayList<Attribute>(numLabels + dataset.numAttributes()); for (int i = 0; i < numLabels; i++) { attrs.add(new Attribute(target.name() + "_" + i, possibleValues)); } for (int i = 0; i < dataset.numAttributes(); i++) { Attribute attr = dataset.attribute(i); Attribute newAttribute = null; if (attr.isNominal() == true) { newAttribute = new Attribute(attr.name(), attr.getAttributeValues()); } if (attr.isNumeric() == true) { newAttribute = new Attribute(attr.name()); } if (newAttribute != null) { attrs.add(newAttribute); } } this.header = new Instances("extended_" + dataset.getRelationName(), attrs, 0); this.header.setClassIndex(numLabels + dataset.classIndex()); }