Good afternoon! I have such method:
private Instances getOneInstanceInstances(Map<String, Double> attributesMap) {
FastVector fvWekaAttributes = new FastVector(attributesMap.size() + 1);
for (String attributeName : attributesMap.keySet()) {
Attribute attribute = new Attribute(attributeName);
fvWekaAttributes.addElement(attribute);
}
FastVector fvClassVal = new FastVector(2);
fvClassVal.addElement(Integer.toString(0));
fvClassVal.addElement(Integer.toString(1));
fvWekaAttributes.addElement(new Attribute("class", fvClassVal));
Instances instances = new Instances("features", fvWekaAttributes,1);
instances.setClassIndex(instances.attribute("class"));
Instance instance = new Instance(fvWekaAttributes.capacity());
instance.setDataset(instances);
for (String attributeName : attributesMap.keySet()) {
Attribute attribute = new Attribute(attributeName);
instance.setValue(attribute, attributesMap.get(attributeName));;
}
instance.setClassMissing();
instances.add(instance);
return instances;
}
And when I run it, it throw
java.lang.ArrayIndexOutOfBoundsException: -1
at weka.core.Instance.setValue(Instance.java:643)
at weka.core.Instance.setValue(Instance.java:716)
at uir.prunning.Prunner.getOneInstanceInstances(Prunner.java:189)
As I think, instance know everything about it's attributes, and everything looks ok for me, but it doesn't work. What's the problem and how can I fix it? Thank you!