An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
<?xml version="1.0" encoding="UTF-8"?><process version="9.6.000-RC"> <context> <input/> <output/> <macros/> </context> <operator activated="true" class="process" compatibility="9.6.000-RC" expanded="true" name="Process"> <parameter key="logverbosity" value="init"/> <parameter key="random_seed" value="-1"/> <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-RC" expanded="true" height="68" name="Create ExampleSet" width="90" x="45" 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="date" value="2020-02-18 00:00:00.1.day"/> </list> <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/> <parameter key="time_zone" value="America/New_York"/> <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-RC" expanded="true" height="82" name="Generate Attributes" width="90" x="179" y="34"> <list key="function_descriptions"> <parameter key="date2" value="date_add(date,rint(1000*rand()),DATE_UNIT_DAY)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">date2 (random add from date)</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-RC" expanded="true" height="82" name="Generate Attributes (2)" width="90" x="313" y="34"> <list key="function_descriptions"> <parameter key="yearMonth" value="100*date_get(date,DATE_UNIT_YEAR)+date_get(date,DATE_UNIT_MONTH)"/> <parameter key="yearMonth2" value="100*date_get(date2,DATE_UNIT_YEAR)+date_get(date2,DATE_UNIT_MONTH)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">yearMonth</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-RC" expanded="true" height="82" name="Generate Attributes (5)" width="90" x="447" y="34"> <list key="function_descriptions"> <parameter key="day" value="date_get(date,DATE_UNIT_DAY)"/> <parameter key="day2" value="date_get(date2,DATE_UNIT_DAY)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">day</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-RC" expanded="true" height="82" name="Generate Attributes (3)" width="90" x="581" y="34"> <list key="function_descriptions"> <parameter key="diffMonth" value="yearMonth2-yearMonth"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">diffMonth</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-RC" expanded="true" height="82" name="Generate Attributes (6)" width="90" x="715" y="34"> <list key="function_descriptions"> <parameter key="diff" value="if(day2<day,diffMonth-1,diffMonth)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">diff</description> </operator> <operator activated="true" class="select_attributes" compatibility="9.6.000-RC" expanded="true" height="82" name="Select Attributes" width="90" x="849" y="34"> <parameter key="attribute_filter_type" value="subset"/> <parameter key="attribute" value=""/> <parameter key="attributes" value="date|date2|diff"/> <parameter key="use_except_expression" value="false"/> <parameter key="value_type" value="attribute_value"/> <parameter key="use_value_type_exception" value="false"/> <parameter key="except_value_type" value="time"/> <parameter key="block_type" value="attribute_block"/> <parameter key="use_block_type_exception" value="false"/> <parameter key="except_block_type" value="value_matrix_row_start"/> <parameter key="invert_selection" value="false"/> <parameter key="include_special_attributes" value="false"/> </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="Generate Attributes (2)" to_port="example set input"/> <connect from_op="Generate Attributes (2)" from_port="example set output" to_op="Generate Attributes (5)" to_port="example set input"/> <connect from_op="Generate Attributes (5)" from_port="example set output" to_op="Generate Attributes (3)" to_port="example set input"/> <connect from_op="Generate Attributes (3)" from_port="example set output" to_op="Generate Attributes (6)" to_port="example set input"/> <connect from_op="Generate Attributes (6)" from_port="example set output" to_op="Select Attributes" to_port="example set input"/> <connect from_op="Select 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"/> </process> </operator> </process>
(date_get(date2, DATE_UNIT_YEAR) - date_get(date, DATE_UNIT_YEAR)) * 12 + (date_get(date2, DATE_UNIT_MONTH) - date_get(date, DATE_UNIT_MONTH))
from dateutil import relativedelta import pandas as pd def rm_main(data): relative_deltas = data.apply(lambda x: relativedelta.relativedelta(pd.to_datetime(x["date2"]), pd.to_datetime(x["date"])), axis = 1) data["Python_RelativeDelta"] = relative_deltas data["Python_DiffInMonths"] = [round(rd.years * 12 + rd.months + rd.days/30.41667) for rd in relative_deltas] return data
<?xml version="1.0" encoding="UTF-8"?><process version="9.6.000-BETA"> <context> <input/> <output/> <macros/> </context> <operator activated="true" class="process" compatibility="9.6.000-BETA" expanded="true" name="Process"> <parameter key="logverbosity" value="init"/> <parameter key="random_seed" value="-1"/> <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-BETA" expanded="true" height="68" name="Create ExampleSet" width="90" x="45" 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="date" value="2020-02-18 00:00:00.1.day"/> </list> <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/> <parameter key="time_zone" value="America/New_York"/> <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-BETA" expanded="true" height="82" name="Generate Attributes" width="90" x="179" y="34"> <list key="function_descriptions"> <parameter key="date2" value="date_add(date,rint(1000*rand()),DATE_UNIT_DAY)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">date2 (random add from date)</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-BETA" expanded="true" height="82" name="Generate Attributes (2)" width="90" x="313" y="34"> <list key="function_descriptions"> <parameter key="yearMonth" value="100*date_get(date,DATE_UNIT_YEAR)+date_get(date,DATE_UNIT_MONTH)"/> <parameter key="yearMonth2" value="100*date_get(date2,DATE_UNIT_YEAR)+date_get(date2,DATE_UNIT_MONTH)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">yearMonth</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-BETA" expanded="true" height="82" name="Generate Attributes (5)" width="90" x="447" y="34"> <list key="function_descriptions"> <parameter key="day" value="date_get(date,DATE_UNIT_DAY)"/> <parameter key="day2" value="date_get(date2,DATE_UNIT_DAY)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">day</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-BETA" expanded="true" height="82" name="Generate Attributes (3)" width="90" x="581" y="34"> <list key="function_descriptions"> <parameter key="diffMonth" value="yearMonth2-yearMonth"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">diffMonth</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-BETA" expanded="true" height="82" name="Generate Attributes (6)" width="90" x="715" y="34"> <list key="function_descriptions"> <parameter key="RapidMiner_DiffInMonths_v1" value="if(day2<day,diffMonth-1,diffMonth)"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">diff</description> </operator> <operator activated="true" class="generate_attributes" compatibility="9.6.000-BETA" expanded="true" height="82" name="Generate Attributes (4)" width="90" x="849" y="34"> <list key="function_descriptions"> <parameter key="RapidMiner_DiffInMonths_v2" value="(date_get(date2, DATE_UNIT_YEAR) - date_get(date, DATE_UNIT_YEAR)) * 12 + (date_get(date2, DATE_UNIT_MONTH) - date_get(date, DATE_UNIT_MONTH))"/> </list> <parameter key="keep_all" value="true"/> </operator> <operator activated="true" class="python_scripting:execute_python" compatibility="9.5.000" expanded="true" height="103" name="Execute Python" width="90" x="983" y="34"> <parameter key="script" value="from dateutil import relativedelta import pandas as pd def rm_main(data): 	relative_deltas = data.apply(lambda x: relativedelta.relativedelta(pd.to_datetime(x["date2"]), pd.to_datetime(x["date"])), axis = 1) 	data["Python_RelativeDelta"] = relative_deltas 	data["Python_DiffInMonths"] = [round(rd.years * 12 + rd.months + rd.days/30.41667) for rd in relative_deltas] 	 	return data "/> <parameter key="notebook_cell_tag_filter" value=""/> <parameter key="use_default_python" value="true"/> <parameter key="package_manager" value="conda (anaconda)"/> </operator> <operator activated="true" class="select_attributes" compatibility="9.6.000-BETA" expanded="true" height="82" name="Select Attributes" width="90" x="1117" y="34"> <parameter key="attribute_filter_type" value="subset"/> <parameter key="attribute" value=""/> <parameter key="attributes" value="date|date2|Python_DiffInMonths|RapidMiner_DiffInMonths_v1|RapidMiner_DiffInMonths_v2|Python_RelativeDelta"/> <parameter key="use_except_expression" value="false"/> <parameter key="value_type" value="attribute_value"/> <parameter key="use_value_type_exception" value="false"/> <parameter key="except_value_type" value="time"/> <parameter key="block_type" value="attribute_block"/> <parameter key="use_block_type_exception" value="false"/> <parameter key="except_block_type" value="value_matrix_row_start"/> <parameter key="invert_selection" value="false"/> <parameter key="include_special_attributes" value="false"/> </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="Generate Attributes (2)" to_port="example set input"/> <connect from_op="Generate Attributes (2)" from_port="example set output" to_op="Generate Attributes (5)" to_port="example set input"/> <connect from_op="Generate Attributes (5)" from_port="example set output" to_op="Generate Attributes (3)" to_port="example set input"/> <connect from_op="Generate Attributes (3)" from_port="example set output" to_op="Generate Attributes (6)" to_port="example set input"/> <connect from_op="Generate Attributes (6)" from_port="example set output" to_op="Generate Attributes (4)" to_port="example set input"/> <connect from_op="Generate Attributes (4)" from_port="example set output" to_op="Execute Python" to_port="input 1"/> <connect from_op="Execute Python" from_port="output 1" to_op="Select Attributes" to_port="example set input"/> <connect from_op="Select 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"/> </process> </operator> </process>