🎉 🎉 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

[SOLVED] Number of Examples in Set

ziszis Member Posts: 22 Contributor II
edited November 2018 in Help
Hi,

I have data in ExampleSet like :
IDNAMEVALUE
1Bob123.0
1Bob456.4
1Bob4786.4
1Alice333.4
1Brad88.4
2Jacob353.4
2Jacob663.4
2Jacob633.4
And now, I need to cut data, that every same name in specific  ID is occurs max twice.
The wanted result is:
IDNAMEVALUE
1Bob123.0
1Bob456.4
1Alice333.4
1Brad88.4
2Jacob353.4
2Jacob663.4
Is that possible in RapidMiner? Any regular expression or something.

Thanks,
Regards,
John

Answers

  • ziszis Member Posts: 22 Contributor II
    I tried a Loop Examples, but is exists something like condition if/else? Data value I extracted by Filter Examples Macro(data value) and if I said that the Example with name Bob is twice or more, then continue. Exists something like Continue operator and Counter operator?
  • Marco_BoeckMarco_Boeck Team Lead Software Engineering Administrator, Moderator, Employee, Member, University Professor Posts: 1,963   RM Engineering
    Hi,

    yes it is possible, but currently I can't think of a way of doing it without the "Execute Script" operator. Basically iterate over the sorted example set, count the number of same names, then flag every example which should be removed and afterwards remove all flagged examples.
    Though you might want and try to come up with something clever using macros (as counter variables) and the "Branch" operator, it might very well be possible ;)

    Regards,
    Marco
  • ziszis Member Posts: 22 Contributor II
    Wow,

    Execution Script seems like a powerful tool. Thanks a lot. I wrote something like that:

    ExampleSet exampleSet = operator.getInput(ExampleSet.class);

    int instanceCounter = 0;
    String lastValue;
    int counter = 0;
    for(Example example : exampleSet)
    {
    String value = example["InstanceID"];

    if(lastValue == value)
    instanceCounter++;
    else
    instanceCounter = 0;

    if(instanceCounter >= 5)
    exampleSet.remove(counter);

    counter++;
    lastValue = value;
    }

    operator.setOutput(exampleSet);
    But it throws Exceptions, that something is wrong with method Remove (seems like a parser doesnt know her). Do you know, how can I remove an Example and at the end returns this new ExampleSet to output port? You were talking about flags. What do you mean?

    Thanks,
    Regards,
    John


  • ziszis Member Posts: 22 Contributor II
    Ok,

    I have changed a method according to IOObject.remove(T class) implementation to exampleSet.remove(example) (from example above), and Exceptions are gone. But the Operator doesnt return the ExampleSet.

    MODIFIED:

    ok now, i can return the ExampleSet, but the method remove is wrong. Without remove method the process proceed well, but I need this method or similar to remove specific Example.
  • ziszis Member Posts: 22 Contributor II
    I have read that you cannot remove Example from ExampleSet while you iterating. So I set names (>2) to value -1. Is any operator, that I can use to remove all examples with NAME attribute and value -1, after Execute Script operator?

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

    you can use the "Filter Examples" operator. Set condition class parameter to "attribute_value_filter" and then simply put in "NAME!=-1" (without the quotes)

    Regards,
    Marco
  • ziszis Member Posts: 22 Contributor II
    Nice one, thanks a lot. Working fine.

    Regards,
    John
Sign In or Register to comment.