The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
creating an exampleset with a label, regulars, ids, etc.
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!
Tagged:
0
Answers
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,
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!