creating an exampleset with a label, regulars, ids, etc.

jjariyasjjariyas Member Posts: 6 Contributor II
edited November 2018 in 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);

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!


  • Options
    fischerfischer Member Posts: 439 Maven

    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);

  • Options
    jjariyasjjariyas Member Posts: 6 Contributor II
    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)
    ExampleSet exampleSet = table.createExampleSet(label);

    Thanks again!
Sign In or Register to comment.