🎉 🎉 RAPIDMINER 9.10 IS OUT!!! 🎉🎉

Download the latest version helping analytics teams accelerate time-to-value for streaming and IIOT use cases.

CLICK HERE TO DOWNLOAD

Add label to existing ExampleSet

radoneradone RapidMiner Certified Expert, Member Posts: 74  Guru
edited November 2018 in Help
Hi,
I have an existing example set. How can I effectively add a label attribute to the existing example set?

ExampleSet newExampleSet = .... (an existing example set);

// ADD LABEL ATTRIBUTE
Attribute label = AttributeFactory.createAttribute("label", Ontology.NOMINAL);
newExampleSet.getAttributes().setLabel(label);

// SET NOMINAL VALUE
Example e = newExampleSet.getExample(0);
e.setLabel(label.getMapping().mapString(clsName));

throws  java.lang.ArrayIndexOutOfBoundsException: -1 on the last line.

SEVERE: Process failed: operator cannot be executed (-1). Check the log messages...
java.lang.ArrayIndexOutOfBoundsException: -1
at com.rapidminer.example.table.DoubleArrayDataRow.set(DoubleArrayDataRow.java:52)
at com.rapidminer.example.table.AbstractAttribute.setValue(AbstractAttribute.java:184)
at com.rapidminer.example.table.DataRow.set(DataRow.java:85)
at com.rapidminer.example.Example.setValue(Example.java:140)
at com.rapidminer.example.Example.setLabel(Example.java:178)
at ... last code of the example above ...
Thanks in advance for any help,
radone
Tagged:

Answers

  • Marco_BoeckMarco_Boeck Team Lead Software Engineering Administrator, Moderator, Employee, Member, University Professor Posts: 1,963   RM Engineering
    Hi,

    this should work:

    Attribute newAtt = AttributeFactory.createAttribute("label", Ontology.NOMINAL);
    newExampleSet.getExampleTable().addAttribute(newAtt);
    newExampleSet.getAttributes().addRegular(newAtt);
    newExampleSet.getAttributes().setSpecialAttribute(newExampleSet.getAttributes().get("label"), "label");
    There are other ways, but this one should work just fine.

    Regards,
    Marco
  • radoneradone RapidMiner Certified Expert, Member Posts: 74  Guru
    Thank you for your reply.

    Unfortunately, ended with exactly the same error. I got some debugging info about the just inserted label and it seems that "-1" in my outpput might have something to do with my problem?

    String clsName = "MY_NEW_NOMINAL_CLASS";
    ExampleSet newExampleSet = .... (an existing example set);

    // ADD LABEL ATTRIBUTE
    Attribute label = AttributeFactory.createAttribute("label", Ontology.NOMINAL);
    newExampleSet.getAttributes().setLabel(label);

    System.out.println(newExampleSet.getAttributes().getLabel());

    // SET NOMINAL VALUE
    Example e = newExampleSet.getExample(0);
    e.setLabel(label.getMapping().mapString(clsName));
    the system out gives:
    #-1: label (nominal/single_value)/values=[]
    and the code:

                   Example e = newExampleSet.getExample(0);
    e.setLabel(label.getMapping().mapString(clsName));
    throws:
    SEVERE: Process failed: operator cannot be executed (-1). Check the log messages...
    java.lang.ArrayIndexOutOfBoundsException: -1
    at com.rapidminer.example.table.DoubleArrayDataRow.set(DoubleArrayDataRow.java:52)
    at com.rapidminer.example.table.AbstractAttribute.setValue(AbstractAttribute.java:184)
    at com.rapidminer.example.table.DataRow.set(DataRow.java:85)
    at com.rapidminer.example.Example.setValue(Example.java:140)
    at com.rapidminer.example.Example.setLabel(Example.java:178)
    at .... last code of the example above ....

  • Marco_BoeckMarco_Boeck Team Lead Software Engineering Administrator, Moderator, Employee, Member, University Professor Posts: 1,963   RM Engineering
    Hi,

    I forgot a line in my first reply, so I had to edit it. If you copy that codeblock, you should be fine.
    Note that to be able to use
    newExampleSet.getAttributes().setLabel(label);
    the label attribute must already be present in the attribute set.

    Regards,
    Marco
  • radoneradone RapidMiner Certified Expert, Member Posts: 74  Guru
    Thank you Marco.

    The line:
    newExampleSet.getExampleTable().addAttribute(newAtt);
    was exactly what I was missing.
Sign In or Register to comment.