creating an exampleset with a label, regulars, ids, etc.
jjariyas
New Altair Community Member
Hi,
Currently I can successfully create an example set with one attribute and one label by doing the following:
List<Attribute> attributes = new LinkedList<Attribute>();
//add the attribute
attributes.add(AttributeFactory.createAttribute("someRegular", Ontology.REAL));
//add the label
Attribute label = AttributeFactory.createAttribute("label", Ontology.NOMINAL);
attributes.add(label);
MemoryExampleTable table = new MemoryExampleTable(attributes);
double[] data = new double[attributes.size()];
data[0] = 5; //arbitrary number for an attribute
data[1] = label.getMapping().mapString("Monkey"); //arbitrary label
//one data row added!
table.addDataRow(new DoubleArrayDataRow(data))
ExampleSet exampleSet = table.createExampleSet(label);
now, i want to put an "id" in here (so the classifier doesn't use it, and only uses the "someRegular").
I've tried playing around with this for quite a while and I just can't seem to get it working.
Another thing I don't understand (since I sort of put this code together from other postings on this board) is how the ExampleSet knows that my attribute "label" is a label. It doesn't seem obvious, and maybe that's why I'm having trouble trying to figure out how to set a different role for another column in my example set.
Thanks for all your help!
Currently I can successfully create an example set with one attribute and one label by doing the following:
List<Attribute> attributes = new LinkedList<Attribute>();
//add the attribute
attributes.add(AttributeFactory.createAttribute("someRegular", Ontology.REAL));
//add the label
Attribute label = AttributeFactory.createAttribute("label", Ontology.NOMINAL);
attributes.add(label);
MemoryExampleTable table = new MemoryExampleTable(attributes);
double[] data = new double[attributes.size()];
data[0] = 5; //arbitrary number for an attribute
data[1] = label.getMapping().mapString("Monkey"); //arbitrary label
//one data row added!
table.addDataRow(new DoubleArrayDataRow(data))
ExampleSet exampleSet = table.createExampleSet(label);
now, i want to put an "id" in here (so the classifier doesn't use it, and only uses the "someRegular").
I've tried playing around with this for quite a while and I just can't seem to get it working.
Another thing I don't understand (since I sort of put this code together from other postings on this board) is how the ExampleSet knows that my attribute "label" is a label. It doesn't seem obvious, and maybe that's why I'm having trouble trying to figure out how to set a different role for another column in my example set.
Thanks for all your help!
0
Answers
-
Hi,
if you already have the attribute in the example table, you can use
exampleSet.getAttributes().setSpecialAttribute(Attribute attribute, String specialName);
or, as a short cut;
exampleSet.getAttributes().setId(Attribute attribute);
Best,
Simon0 -
Much appreciated Simon!
Thats exactly what I needed to know. If anyone else encounters the same problem, you can do
Attribute idAttribute = AttributeFactory.createAttribute("someID", Ontology.REAL)
attributes.add(idAttribute);
...
ExampleSet exampleSet = table.createExampleSet(label);
exampleSet.getAttributes().setId(idAttribute);
Thanks again!0