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

[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 Administrator, Moderator, Employee-RapidMiner, Member, University Professor Posts: 1,996 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 Administrator, Moderator, Employee-RapidMiner, Member, University Professor Posts: 1,996 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.