increment filter example

jhiKl
jhiKl New Altair Community Member
edited November 2024 in Community Q&A
Hi i'm new in rapidminer and have tried the possible ways to achieve my result but i'm having a hard time achieving it. How can I increment filter example? I'm working on a data set that gets the top 3 items per month. What i got to do is loop through the example set but my example filter is always in the month 1 only.
My example set
item id, month, sales
1, jan, 25
2 jan, 45
3, jan, 56
4, jan, 36
Expected result
3, jan, 56
2, jan, 45
4, jan, 36 and so on..

Best Answers

  • BalazsBaranyRM
    BalazsBaranyRM New Altair Community Member
    Answer ✓
    Hi @jhiKI,

    if I understand you correctly, you're trying to determine the top 3 entries of each month.

    You could use Loop Values with the month attribute. In the loop you'd filter for the current month (loop_value macro), sort the result by sales descending, and Filter Example Range from 1 to 3. Then you would use Append to put the resulting collection together again.

    It also works with the Database Envy extension which you can install from the Marketplace. 
    Here, you would use Generate Attribute to create the negSales attribute from sales with the formula "0 - sales". This is necessary because you want to sort by the sales and Database Envy can't yet sort descending. Then you use Apply Window Function: function: rank, group attributes: month, order attribute: negSales, value attribute: sales. This gives you the monthly rank of each entry (ties are possible), and you can use Filter examples to filter rank <= 3.

    Regards,
    Balázs

  • jhiKl
    jhiKl New Altair Community Member
    Answer ✓
    Thank you for your help I finally did it!

    Appreciatively,
    jhikl

Answers

  • BalazsBaranyRM
    BalazsBaranyRM New Altair Community Member
    Answer ✓
    Hi @jhiKI,

    if I understand you correctly, you're trying to determine the top 3 entries of each month.

    You could use Loop Values with the month attribute. In the loop you'd filter for the current month (loop_value macro), sort the result by sales descending, and Filter Example Range from 1 to 3. Then you would use Append to put the resulting collection together again.

    It also works with the Database Envy extension which you can install from the Marketplace. 
    Here, you would use Generate Attribute to create the negSales attribute from sales with the formula "0 - sales". This is necessary because you want to sort by the sales and Database Envy can't yet sort descending. Then you use Apply Window Function: function: rank, group attributes: month, order attribute: negSales, value attribute: sales. This gives you the monthly rank of each entry (ties are possible), and you can use Filter examples to filter rank <= 3.

    Regards,
    Balázs

  • jhiKl
    jhiKl New Altair Community Member
    edited March 2020
    Hi, sorry whenever I connect my loop value to the set macro it does not show any attributes. Do you guys happen to know why? It seems like it cannot get my data.
  • jhiKl
    jhiKl New Altair Community Member
    Answer ✓
    Thank you for your help I finally did it!

    Appreciatively,
    jhikl