The Altair Community is migrating to a new platform to provide a better experience for you. The RapidMiner Community will merge with the Altair Community at the same time. In preparation for the migration, both communities are on read-only mode from July 15th - July 24th, 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.

Create macros dynamically according to data

phivuphivu Member Posts: 34 Guru
edited November 2018 in Help

Hi RapidMiner,


I'm doing predictive maintenance, I have a data table containing a list of fault types and their corresponding percentages (as below). What I want is to create a macro for each fault type storing the percentage value. Because the size of the list may change overtime, I want a dynamic way to create the macros (# of macros= # of fault types). These macros will be reused many times later. Is there a way to do this? Thanks a lot for your help!



MECH 0.26

PROD 0.13

ELEC 0.11


SOFT 0.06


UPG 0.01

Best Answers

  • Options
    MartinLiebigMartinLiebig Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,525 RM Data Scientist
    Solution Accepted


    Loop Examples + Extract macro should do the job :).



    - Sr. Director Data Solutions, Altair RapidMiner -
    Dortmund, Germany
  • Options
    JEdwardJEdward RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 578 Unicorn
    Solution Accepted

    Yes it is.  I often do it for cases where the number of fields might change. 


    One thing to think about in your process is how you will use those macros when they are generated... especially if they will be reused many times over. 

    You might find it more convenient to (rather than a macro) create a table which stores all the fault values and percentages and just recall that when required and extract the necessary value.  Here's an example process showing both methods. 


    <?xml version="1.0" encoding="UTF-8"?><process version="7.3.000">
    <operator activated="true" class="process" compatibility="7.3.000" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve Iris" width="90" x="45" y="34">
    <parameter key="repository_entry" value="//Samples/data/Iris"/>
    <operator activated="true" class="loop_attributes" compatibility="7.3.000" expanded="true" height="82" name="Loop Attributes" width="90" x="179" y="34">
    <process expanded="true">
    <operator activated="true" class="extract_macro" compatibility="7.3.000" expanded="true" height="68" name="Extract Macro" width="90" x="112" y="34">
    <parameter key="macro" value="DynamicMacro_%{loop_attribute}_Average"/>
    <parameter key="macro_type" value="statistics"/>
    <parameter key="attribute_name" value="%{loop_attribute}"/>
    <list key="additional_macros"/>
    <connect from_port="example set" to_op="Extract Macro" to_port="example set"/>
    <connect from_op="Extract Macro" from_port="example set" to_port="example set"/>
    <portSpacing port="source_example set" spacing="0"/>
    <portSpacing port="sink_example set" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <operator activated="true" class="generate_data_user_specification" compatibility="7.3.000" expanded="true" height="68" name="Extract Value of Macro" width="90" x="581" y="34">
    <list key="attribute_values">
    <parameter key="a1_average" value="%{DynamicMacro_a1_Average}"/>
    <list key="set_additional_roles"/>
    <description align="center" color="transparent" colored="false" width="126">Select the macro you want dynamically when required.</description>
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve Iris (2)" width="90" x="45" y="391">
    <parameter key="repository_entry" value="//Samples/data/Iris"/>
    <operator activated="true" class="aggregate" compatibility="7.3.000" expanded="true" height="82" name="Aggregate" width="90" x="179" y="391">
    <parameter key="use_default_aggregation" value="true"/>
    <list key="aggregation_attributes"/>
    <operator activated="true" class="remember" compatibility="7.3.000" expanded="true" height="68" name="Remember" width="90" x="313" y="391">
    <parameter key="name" value="MyDataSet"/>
    <operator activated="true" class="recall" compatibility="7.3.000" expanded="true" height="68" name="Recall" width="90" x="581" y="391">
    <parameter key="name" value="MyDataSet"/>
    <parameter key="remove_from_store" value="false"/>
    <description align="center" color="transparent" colored="false" width="126">Select the value you want dynamically when required.</description>
    <connect from_op="Retrieve Iris" from_port="output" to_op="Loop Attributes" to_port="example set"/>
    <connect from_op="Extract Value of Macro" from_port="output" to_port="result 1"/>
    <connect from_op="Retrieve Iris (2)" from_port="output" to_op="Aggregate" to_port="example set input"/>
    <connect from_op="Aggregate" from_port="example set output" to_op="Remember" to_port="store"/>
    <connect from_op="Recall" from_port="result" to_port="result 2"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="336"/>
    <portSpacing port="sink_result 3" spacing="0"/>
    <description align="center" color="yellow" colored="false" height="69" resized="true" width="401" x="26" y="177">Method 1, Dynamically Create Macros</description>
    <description align="center" color="yellow" colored="false" height="69" resized="false" width="401" x="27" y="493">Method 2, Creating a table &amp;amp; storing in memory</description>
Sign In or Register to comment.