Convert datetime attribute(time) to morning, afternoon,evening,night

gohelgohel Member Posts: 6 Contributor I
Hi all,
I was trying to convert time into morning afternoon,evening and night, and using Discretize by User Specification but it's not helping me out.
Can someone help me in doing the process in Generate atribute operator?
In my project it is..
Morning- 6am to 11am
Afternoon- 11am - 4pm
Evening- 4pm- 11pm



  • Options
    hbajpaihbajpai Member Posts: 102 Unicorn
    Hey @gohel ,

    You can use recursive if else block in generate attributes to take care of this as your limits are consistent for "Night".
    if( Hour > 6 && Hour <= 11, "Day", 
    	if ( Hour > 11 && Hour <=16, "Afternoon", 
    		if( Hour >16 && Hour <= 23, "Evening" , "Night")))
    Example XML Code as follows:
    <?xml version="1.0" encoding="UTF-8"?><process version="9.6.000">
      <operator activated="true" class="process" compatibility="9.6.000" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" class="utility:create_exampleset" compatibility="9.6.000" expanded="true" height="68" name="Create ExampleSet" width="90" x="112" y="34">
            <parameter key="generator_type" value="date series"/>
            <parameter key="number_of_examples" value="100"/>
            <parameter key="use_stepsize" value="true"/>
            <list key="function_descriptions"/>
            <parameter key="add_id_attribute" value="false"/>
            <list key="numeric_series_configuration"/>
            <list key="date_series_configuration"/>
            <list key="date_series_configuration (interval)">
              <parameter key="DateTime" value="2020-04-21 10:00:00.1.hour"/>
            <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="column_separator" value=","/>
            <parameter key="parse_all_as_nominal" value="false"/>
            <parameter key="decimal_point_character" value="."/>
            <parameter key="trim_attribute_names" value="true"/>
          <operator activated="true" class="generate_attributes" compatibility="9.6.000" expanded="true" height="82" name="Generate Attributes" width="90" x="380" y="34">
            <list key="function_descriptions">
              <parameter key="Hour" value="date_get(DateTime,DATE_UNIT_HOUR)"/>
              <parameter key="Time of Day" value="if( Hour &gt; 6 &amp;&amp; Hour &lt;= 11, &quot;Day&quot;, &#10;&#9;if ( Hour &gt; 11 &amp;&amp; Hour &lt;=16, &quot;Afternoon&quot;, &#10;&#9;&#9;if( Hour &gt;16 &amp;&amp; Hour &lt;= 23, &quot;Evening&quot; , &quot;Night&quot;)))"/>
            <parameter key="keep_all" value="true"/>
          <connect from_op="Create ExampleSet" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" from_port="example set output" 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"/>

  • Options
    Telcontar120Telcontar120 Moderator, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 Unicorn
    You actually can use Discretize by User Specification, you simply need to create a separate group for the 0-6 values and classify it as "Night" as well as a group for the 23+ values (also classified as "Night").  Meaning you can map different non-contiguous values to the same outcome with this operator.

    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
Sign In or Register to comment.