The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 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
Date_time to be discretized (morning afternoon, evening)
Hi all,
I want to convert time attribute (of type date time) into three categories- [morning, afternoon and evening], and I used Discretize by user specification operator for it but it's not helping me out.
For example-
6AM to 11AM- morning
11AM to 4 PM- afternoon
4PM to 10 PM- evening
Can anyone help me out?
Thanks
I want to convert time attribute (of type date time) into three categories- [morning, afternoon and evening], and I used Discretize by user specification operator for it but it's not helping me out.
For example-
6AM to 11AM- morning
11AM to 4 PM- afternoon
4PM to 10 PM- evening
Can anyone help me out?
Thanks
0
Best Answer
-
David_A Administrator, Moderator, Employee-RapidMiner, RMResearcher, Member Posts: 297 RM ResearchHi @gohel ,what you need to do is first extract the hours each day. This can be done with the Generate Attributes operator and the date_get() function.The Discretize by user specification operator has the drawback, that you can only specify upper limits to your classes, so creating a category "night" that goes from 22PM - 6AM is tricky.That's why I would again use Generate Attributes and a stacked if-else statement for all cases, see the process xml below for an example.Best,
David<?xml version="1.0" encoding="UTF-8"?><process version="9.6.000">
<context>
<input/>
<output/>
<macros/>
</context>
<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="179" y="34">
<parameter key="generator_type" value="date series"/>
<parameter key="number_of_examples" value="100"/>
<parameter key="use_stepsize" value="false"/>
<list key="function_descriptions"/>
<parameter key="add_id_attribute" value="false"/>
<list key="numeric_series_configuration"/>
<list key="date_series_configuration">
<parameter key="Time" value="2020-04-20 12:00:00.2020-04-30 12:00:00"/>
</list>
<list key="date_series_configuration (interval)"/>
<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>
<operator activated="true" class="generate_attributes" compatibility="9.6.000" expanded="true" height="82" name="Generate Attributes" width="90" x="447" y="34">
<list key="function_descriptions">
<parameter key="extract_hour" value="date_get(Time,DATE_UNIT_HOUR)"/>
<parameter key="get_day_time" value="if(extract_hour<6,"evening", if(extract_hour<11,"morning", if(extract_hour<16,"afternoon",if(extract_hour<22,"evening","morning"))))"/>
<parameter key="extract_hour_2" value="extract_hour"/>
</list>
<parameter key="keep_all" value="true"/>
</operator>
<operator activated="true" class="discretize_by_user_specification" compatibility="9.6.000" expanded="true" height="103" name="Discretize" width="90" x="715" y="34">
<parameter key="return_preprocessing_model" value="false"/>
<parameter key="create_view" value="false"/>
<parameter key="attribute_filter_type" value="single"/>
<parameter key="attribute" value="extract_hour"/>
<parameter key="attributes" value=""/>
<parameter key="use_except_expression" value="false"/>
<parameter key="value_type" value="numeric"/>
<parameter key="use_value_type_exception" value="false"/>
<parameter key="except_value_type" value="real"/>
<parameter key="block_type" value="value_series"/>
<parameter key="use_block_type_exception" value="false"/>
<parameter key="except_block_type" value="value_series_end"/>
<parameter key="invert_selection" value="false"/>
<parameter key="include_special_attributes" value="false"/>
<list key="classes">
<parameter key="night" value="6.0"/>
<parameter key="morning" value="11.0"/>
<parameter key="afternoon" value="16.0"/>
<parameter key="evening" value="22.0"/>
<parameter key="night" value="24.0"/>
</list>
</operator>
<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_op="Discretize" to_port="example set input"/>
<connect from_op="Discretize" 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"/>
</process>
</operator>
</process>
2