increment filter example

jhiKl
New Altair Community Member
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..
0
Best Answers
-
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
2 -
Hi,
you don't need Set Macro in this process. Loop Values sets a macro to the value of the current iteration. You can access this macro value with %{loop_value} in Filter Examples.
Set Macro doesn't show you any attributes, that's how it is supposed to work. It just sets a macro value that you enter.
Extract Macro can be used to extract properties or values from example sets, but you don't need it here.
Regards,
Balázs5 -
Thank you for your help I finally did it!Appreciatively,jhikl-1
Answers
-
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
2 -
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.
0 -
Hi,
you don't need Set Macro in this process. Loop Values sets a macro to the value of the current iteration. You can access this macro value with %{loop_value} in Filter Examples.
Set Macro doesn't show you any attributes, that's how it is supposed to work. It just sets a macro value that you enter.
Extract Macro can be used to extract properties or values from example sets, but you don't need it here.
Regards,
Balázs5 -
Thank you for your help I finally did it!Appreciatively,jhikl-1