Due to recent updates, all users are required to create an Altair One account to login to the RapidMiner community. Click the Register button to create your account using the same email that you have previously used to login to the RapidMiner community. This will ensure that any previously created content will be synced to your Altair One account. Once you login, you will be asked to provide a username that identifies you to other Community users. Email us at Community with questions.

Loop which sets a mark from a time interval

felix_wfelix_w Member Posts: 61 Contributor II
edited December 2018 in Help

Dear Rapidminer Community, 

 

I got a problem which I hope you can help me with! 

 

I have a time interval, lets say from 27th of November 3pm to 7pm and what I would like to do is that I take this interval and mark all the hours within this interval on a 24h basis. 

 

Like this: 

27th November 1 AM

27th November 2 AM

27th November 3 AM

27th November 4 AM 

....

27th November 2 PM

27th November 3 PM   X (the mark)

27th November 4 PM   X (the mark)

27th November 5 PM   X (the mark)

27th November 6 PM   X (the mark)

27th November 7 PM   X (the mark)

27th November 8 PM

27th November 9 PM 

....

 

I tried to solve this with a generate attribute operator and an "if clause" but I didn't manage to get any proper results!

 

Is there any way to solve this? 

 

Best regards

Felix

Answers

  • JEdwardJEdward RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 578 Unicorn

    Hi Felix,

     

    You can use a couple of ways, but Generate Attributes should work fine for you.  See these examples.

     

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.6.001">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.6.001" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="operator_toolbox:generate_univariate_series" compatibility="0.6.001" expanded="true" height="68" name="Generate Univariate Series" width="90" x="45" y="85">
    <parameter key="data_type" value="DATE_TIME"/>
    <parameter key="startdate" value="2017-11-26 00:00:00"/>
    <parameter key="enddate" value="2017-11-28 00:00:00"/>
    <parameter key="intervaltype" value="HOUR"/>
    </operator>
    <operator activated="true" class="filter_examples" compatibility="7.6.001" expanded="true" height="103" name="Filter Examples" width="90" x="179" y="85">
    <list key="filters_list">
    <parameter key="filters_entry_key" value="att1.le.11/27/2017 7:00:00 PM"/>
    <parameter key="filters_entry_key" value="att1.ge.11/27/2017 3:00:00 PM"/>
    </list>
    </operator>
    <operator activated="true" class="generate_empty_attribute" compatibility="7.6.001" expanded="true" height="82" name="Generate Empty Attribute" width="90" x="313" y="187">
    <parameter key="name" value="mark"/>
    <parameter key="value_type" value="polynominal"/>
    </operator>
    <operator activated="true" class="generate_attributes" compatibility="7.6.001" expanded="true" height="82" name="Generate Attributes" width="90" x="313" y="85">
    <list key="function_descriptions">
    <parameter key="mark" value="&quot;X&quot;"/>
    </list>
    </operator>
    <operator activated="true" class="append" compatibility="7.6.001" expanded="true" height="103" name="Append" width="90" x="447" y="85"/>
    <operator activated="true" class="sort" compatibility="7.6.001" expanded="true" height="82" name="Sort" width="90" x="581" y="85">
    <parameter key="attribute_name" value="att1"/>
    </operator>
    <operator activated="true" class="operator_toolbox:generate_univariate_series" compatibility="0.6.001" expanded="true" height="68" name="Generate Univariate Series (2)" width="90" x="45" y="391">
    <parameter key="data_type" value="DATE_TIME"/>
    <parameter key="startdate" value="2017-11-26 00:00:00"/>
    <parameter key="enddate" value="2017-11-28 00:00:00"/>
    <parameter key="intervaltype" value="HOUR"/>
    </operator>
    <operator activated="true" class="generate_attributes" compatibility="7.6.001" expanded="true" height="82" name="Generate Attributes (2)" width="90" x="179" y="391">
    <list key="function_descriptions">
    <parameter key="mark" value="if(&#10;date_after(att1,date_parse_custom(&quot;201711271459&quot;,&quot;yyyyMMddHHmm&quot;)) &amp;&amp; date_before(att1,date_parse_custom(&quot;201711271901&quot;,&quot;yyyyMMddHHmm&quot;)),&quot;X&quot;,MISSING_NOMINAL)"/>
    </list>
    </operator>
    <connect from_op="Generate Univariate Series" from_port="output" to_op="Filter Examples" to_port="example set input"/>
    <connect from_op="Filter Examples" from_port="example set output" to_op="Generate Attributes" to_port="example set input"/>
    <connect from_op="Filter Examples" from_port="unmatched example set" to_op="Generate Empty Attribute" to_port="example set input"/>
    <connect from_op="Generate Empty Attribute" from_port="example set output" to_op="Append" to_port="example set 2"/>
    <connect from_op="Generate Attributes" from_port="example set output" to_op="Append" to_port="example set 1"/>
    <connect from_op="Append" from_port="merged set" to_op="Sort" to_port="example set input"/>
    <connect from_op="Sort" from_port="example set output" to_port="result 1"/>
    <connect from_op="Generate Univariate Series (2)" from_port="output" to_op="Generate Attributes (2)" to_port="example set input"/>
    <connect from_op="Generate Attributes (2)" from_port="example set output" 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="105" resized="false" width="180" x="426" y="221">Route one.</description>
    <description align="center" color="yellow" colored="false" height="105" resized="false" width="180" x="315" y="430">Route two. 1 operator</description>
    </process>
    </operator>
    </process>
  • Telcontar120Telcontar120 RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 Unicorn
    There is an operator in the Toolbox extension called "Generate Univariate Series" which will also do something similar for you.
    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
  • felix_wfelix_w Member Posts: 61 Contributor II

    Thank you very much for your quick help! :) 

     

    Is there also a loop which can go through a high amount of those intervals (~1000)? Because right now, this solutions works only for one specific date, right?! 

     

     

  • Telcontar120Telcontar120 RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 Unicorn
    Yes, you should be able to go through and use a loop to generate your desired intervals---you'll want to set macros for start and end date (if you are using Generate Univariate Series) based on the values from your dataset, and then loop over them.
    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
  • felix_wfelix_w Member Posts: 61 Contributor II

    Can I do this with Loop Examples? Because the intervals are below each other. 

  • JEdwardJEdward RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 578 Unicorn

    Something like this would work @felix_w

    You can load a list of dates to mark here and the process will mark any number of them. 

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.6.001">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.6.001" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="operator_toolbox:generate_univariate_series" compatibility="0.6.001" expanded="true" height="68" name="Generate Univariate Series (2)" width="90" x="45" y="34">
    <parameter key="data_type" value="DATE_TIME"/>
    <parameter key="startdate" value="2017-10-31 00:00:00"/>
    <parameter key="enddate" value="2017-12-28 00:00:00"/>
    <parameter key="intervaltype" value="HOUR"/>
    </operator>
    <operator activated="true" class="generate_empty_attribute" compatibility="7.6.001" expanded="true" height="82" name="Generate Empty Attribute" width="90" x="246" y="34">
    <parameter key="name" value="mark"/>
    <parameter key="value_type" value="polynominal"/>
    </operator>
    <operator activated="true" class="operator_toolbox:create_exampleset_from_doc" compatibility="0.6.001" expanded="true" height="68" name="Create ExampleSet" width="90" x="45" y="187">
    <parameter key="Input Csv" value="markDates,starthour,markhours&#10;2017-11-01,2,5&#10;2017-11-27,15,3&#10;2017-11-22,3,4&#10;"/>
    <description align="center" color="transparent" colored="false" width="126">Put your dates to mark here. &lt;br/&gt;Format date, hour to start the mark, hour to finish it.</description>
    </operator>
    <operator activated="true" class="extract_macro" compatibility="7.6.001" expanded="true" height="68" name="Extract Macro (2)" width="90" x="179" y="187">
    <parameter key="macro" value="loopNum"/>
    <parameter key="statistics" value="count"/>
    <list key="additional_macros"/>
    </operator>
    <operator activated="true" class="concurrency:loop" compatibility="7.6.001" expanded="true" height="103" name="Loop" width="90" x="447" y="34">
    <parameter key="number_of_iterations" value="%{loopNum}"/>
    <parameter key="reuse_results" value="true"/>
    <process expanded="true">
    <operator activated="true" class="extract_macro" compatibility="7.6.001" expanded="true" height="68" name="Extract Macro" width="90" x="112" y="85">
    <parameter key="macro" value="starthour"/>
    <parameter key="macro_type" value="data_value"/>
    <parameter key="attribute_name" value="starthour"/>
    <parameter key="example_index" value="%{iteration}"/>
    <list key="additional_macros">
    <parameter key="markhours" value="markhours"/>
    <parameter key="markDates" value="markDates"/>
    </list>
    </operator>
    <operator activated="true" class="free_memory" compatibility="7.6.001" expanded="true" height="103" name="Free Memory" width="90" x="313" y="34"/>
    <operator activated="true" class="generate_attributes" compatibility="7.6.001" expanded="true" height="82" name="Generate Attributes (2)" width="90" x="514" y="34">
    <list key="function_descriptions">
    <parameter key="mark" value="if(&#10;date_after(att1,date_add(date_parse_custom(%{markDates},&quot;yyyy-MM-dd&quot;),eval(%{starthour})-1,DATE_UNIT_HOUR)) &amp;&amp; &#10;date_before(att1,date_add(date_parse_custom(%{markDates},&quot;yyyy-MM-dd&quot;),eval(%{starthour})+eval(%{markhours}),DATE_UNIT_HOUR)) &#10;,&quot;X&quot;,mark)"/>
    </list>
    </operator>
    <connect from_port="input 1" to_op="Free Memory" to_port="through 1"/>
    <connect from_port="input 2" to_op="Extract Macro" to_port="example set"/>
    <connect from_op="Extract Macro" from_port="example set" to_op="Free Memory" to_port="through 2"/>
    <connect from_op="Free Memory" from_port="through 1" to_op="Generate Attributes (2)" to_port="example set input"/>
    <connect from_op="Free Memory" from_port="through 2" to_port="output 2"/>
    <connect from_op="Generate Attributes (2)" from_port="example set output" to_port="output 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="source_input 2" spacing="63"/>
    <portSpacing port="source_input 3" spacing="0"/>
    <portSpacing port="sink_output 1" spacing="0"/>
    <portSpacing port="sink_output 2" spacing="0"/>
    <portSpacing port="sink_output 3" spacing="0"/>
    </process>
    </operator>
    <connect from_op="Generate Univariate Series (2)" from_port="output" to_op="Generate Empty Attribute" to_port="example set input"/>
    <connect from_op="Generate Empty Attribute" from_port="example set output" to_op="Loop" to_port="input 1"/>
    <connect from_op="Create ExampleSet" from_port="output" to_op="Extract Macro (2)" to_port="example set"/>
    <connect from_op="Extract Macro (2)" from_port="example set" to_op="Loop" to_port="input 2"/>
    <connect from_op="Loop" from_port="output 1" to_port="result 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="0"/>
    <description align="center" color="yellow" colored="false" height="60" resized="true" width="315" x="492" y="197">This has no bug fixing at all.</description>
    </process>
    </operator>
    </process>
  • felix_wfelix_w Member Posts: 61 Contributor II

    Thank you again for your great help! I will try that tomorrow! :) 

Sign In or Register to comment.