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

Problems about the Operator "Loop"

RichardtheboyRichardtheboy Member Posts: 7 Contributor II
edited November 2018 in Help

Hi guys, I am working on a Financial Time Series Model which tries to predict the accurate stock values (I know that's nearly impossible but I will still give it a try :p )

 

I am now stuck on the "Loop" operator because of the following result. The prediction result is just a continous repeat of the first forecasted value, and the date is wrong (The last date of my inputed data should be 19/09/16, but it turns out the predicted date starts from 10/07/17).

 

Inside my loop, I have put -

1. Apply Model

2. Generate Attributes

(The Generated Attribute would be : Date date_add(Date,eval(%{loop_forecasts}),DATE_UNIT_DAY))

3. Set Role

4. Select Attribute (The value that I would like to predict)

5. Replace (with iteration: %(futureDays)) 

 

May I know which part of my process may have gone wrong? And any solutions for solving this problem?
Thanks :) !

Screen Shot 2016-10-14 at 10.49.48 PM.png

Answers

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn

    I fixed that loop error and cleaned up the process a bit. :)

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.2.003">
    <context>
    <input/>
    <output/>
    <macros>
    <macro>
    <key>horizon</key>
    <value>5</value>
    </macro>
    <macro>
    <key>symbol</key>
    <value>^GSPC</value>
    </macro>
    <macro>
    <key>start_date</key>
    <value>2016-01-01</value>
    </macro>
    <macro>
    <key>end_date</key>
    <value>2016-10-07</value>
    </macro>
    </macros>
    </context>
    <operator activated="true" class="process" compatibility="6.0.002" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="false" class="optimize_parameters_grid" compatibility="7.2.003" expanded="true" height="103" name="Optimize Parameters (Grid)" width="90" x="581" y="238">
    <list key="parameters">
    <parameter key="SVM.kernel_gamma" value="[0.001;1000;6;logarithmic]"/>
    <parameter key="SVM.C" value="[0;1000;10;linear]"/>
    </list>
    <process expanded="true">
    <operator activated="true" class="series:sliding_window_validation" compatibility="7.2.000" expanded="true" height="124" name="Validation" width="90" x="112" y="34">
    <parameter key="training_window_width" value="20"/>
    <parameter key="training_window_step_size" value="1"/>
    <parameter key="test_window_width" value="20"/>
    <parameter key="horizon" value="%{futureDays}"/>
    <process expanded="true">
    <operator activated="true" class="support_vector_machine" compatibility="7.2.003" expanded="true" height="124" name="SVM" width="90" x="179" y="34"/>
    <connect from_port="training" to_op="SVM" to_port="training set"/>
    <connect from_op="SVM" from_port="model" to_port="model"/>
    <portSpacing port="source_training" spacing="0"/>
    <portSpacing port="sink_model" spacing="0"/>
    <portSpacing port="sink_through 1" spacing="0"/>
    </process>
    <process expanded="true">
    <operator activated="true" class="apply_model" compatibility="7.2.003" expanded="true" height="82" name="Apply Model (2)" width="90" x="45" y="34">
    <list key="application_parameters"/>
    </operator>
    <operator activated="true" class="series:forecasting_performance" compatibility="7.2.000" expanded="true" height="82" name="Performance" width="90" x="246" y="34">
    <parameter key="horizon" value="%{futureDays}"/>
    <parameter key="main_criterion" value="prediction_trend_accuracy"/>
    </operator>
    <connect from_port="model" to_op="Apply Model (2)" to_port="model"/>
    <connect from_port="test set" to_op="Apply Model (2)" to_port="unlabelled data"/>
    <connect from_op="Apply Model (2)" from_port="labelled data" to_op="Performance" to_port="labelled data"/>
    <connect from_op="Performance" from_port="performance" to_port="averagable 1"/>
    <portSpacing port="source_model" spacing="0"/>
    <portSpacing port="source_test set" spacing="0"/>
    <portSpacing port="source_through 1" spacing="0"/>
    <portSpacing port="sink_averagable 1" spacing="0"/>
    <portSpacing port="sink_averagable 2" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="log" compatibility="7.2.003" expanded="true" height="82" name="Log" width="90" x="313" y="85">
    <parameter key="filename" value="tmp"/>
    <list key="log">
    <parameter key="Gamma" value="operator.SVM.parameter.kernel_gamma"/>
    <parameter key="C" value="operator.SVM.parameter.C"/>
    <parameter key="Forecast Perf" value="operator.Validation.value.performance"/>
    </list>
    </operator>
    <connect from_port="input 1" to_op="Validation" to_port="training"/>
    <connect from_op="Validation" from_port="averagable 1" to_op="Log" to_port="through 1"/>
    <connect from_op="Log" from_port="through 1" to_port="performance"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="source_input 2" spacing="0"/>
    <portSpacing port="sink_performance" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="quantx1:yahoo_historical_data_extractor" compatibility="1.0.006" expanded="true" height="82" name="Yahoo Historical Stock Data" width="90" x="45" y="34">
    <parameter key="I agree to abide by Yahoo's Terms &amp; Conditions on financial data usage" value="true"/>
    <parameter key="Quick Stock Ticker Data" value="true"/>
    <parameter key="Stock Ticker" value="%{symbol}"/>
    <parameter key="select_fields" value="CLOSE"/>
    <parameter key="date_format" value="yyyy-MM-dd"/>
    <parameter key="date_start" value="%{start_date}"/>
    <parameter key="date_end" value="%{end_date}"/>
    </operator>
    <operator activated="true" class="set_role" compatibility="5.3.013" expanded="true" height="82" name="Set Role" width="90" x="179" y="34">
    <parameter key="attribute_name" value="Date"/>
    <parameter key="target_role" value="id"/>
    <list key="set_additional_roles"/>
    </operator>
    <operator activated="true" class="rename" compatibility="7.2.003" expanded="true" height="82" name="Rename" width="90" x="179" y="136">
    <parameter key="old_name" value="%{symbol}_CLOSE"/>
    <parameter key="new_name" value="Close"/>
    <list key="rename_additional_attributes"/>
    </operator>
    <operator activated="true" class="select_attributes" compatibility="7.2.003" expanded="true" height="82" name="Select Attributes" width="90" x="179" y="238">
    <parameter key="attribute_filter_type" value="subset"/>
    <parameter key="attributes" value="Close|Date"/>
    </operator>
    <operator activated="true" class="filter_examples" compatibility="6.4.000" expanded="true" height="103" name="Filter Examples" width="90" x="179" y="340">
    <parameter key="condition_class" value="no_missing_attributes"/>
    <list key="filters_list"/>
    </operator>
    <operator activated="true" class="series:windowing" compatibility="7.2.000" expanded="true" height="82" name="Windowing" width="90" x="380" y="34">
    <parameter key="window_size" value="6"/>
    <parameter key="create_label" value="true"/>
    <parameter key="label_attribute" value="Close"/>
    </operator>
    <operator activated="true" class="series:windowing" compatibility="7.2.000" expanded="true" height="82" name="Windowing (2)" width="90" x="380" y="136">
    <parameter key="window_size" value="6"/>
    <parameter key="label_attribute" value="Close"/>
    </operator>
    <operator activated="true" class="extract_macro" compatibility="7.2.003" expanded="true" height="68" name="Extract Macro" width="90" x="380" y="238">
    <parameter key="macro" value="n_examples"/>
    <list key="additional_macros"/>
    </operator>
    <operator activated="true" class="generate_macro" compatibility="7.2.003" expanded="true" height="82" name="Generate Macro" width="90" x="380" y="340">
    <list key="function_descriptions">
    <parameter key="filter_range" value="eval(%{n_examples})-1"/>
    </list>
    </operator>
    <operator activated="true" class="filter_example_range" compatibility="7.2.003" expanded="true" height="82" name="Filter Example Range" width="90" x="380" y="442">
    <parameter key="first_example" value="1"/>
    <parameter key="last_example" value="%{filter_range}"/>
    <parameter key="invert_filter" value="true"/>
    </operator>
    <operator activated="true" class="remember" compatibility="7.2.003" expanded="true" height="68" name="Remember" width="90" x="514" y="442">
    <parameter key="name" value="LastRow"/>
    </operator>
    <operator activated="true" class="series:sliding_window_validation" compatibility="7.2.000" expanded="true" height="124" name="Validation (2)" width="90" x="581" y="34">
    <parameter key="training_window_width" value="20"/>
    <parameter key="training_window_step_size" value="1"/>
    <parameter key="test_window_width" value="20"/>
    <parameter key="horizon" value="%{horizon}"/>
    <process expanded="true">
    <operator activated="true" class="support_vector_machine" compatibility="7.2.003" expanded="true" height="124" name="SVM (2)" width="90" x="179" y="34"/>
    <connect from_port="training" to_op="SVM (2)" to_port="training set"/>
    <connect from_op="SVM (2)" from_port="model" to_port="model"/>
    <portSpacing port="source_training" spacing="0"/>
    <portSpacing port="sink_model" spacing="0"/>
    <portSpacing port="sink_through 1" spacing="0"/>
    </process>
    <process expanded="true">
    <operator activated="true" class="apply_model" compatibility="7.2.003" expanded="true" height="82" name="Apply Model (3)" width="90" x="45" y="34">
    <list key="application_parameters"/>
    </operator>
    <operator activated="true" class="series:forecasting_performance" compatibility="7.2.000" expanded="true" height="82" name="Performance (2)" width="90" x="246" y="34">
    <parameter key="horizon" value="%{horizon}"/>
    <parameter key="main_criterion" value="prediction_trend_accuracy"/>
    </operator>
    <connect from_port="model" to_op="Apply Model (3)" to_port="model"/>
    <connect from_port="test set" to_op="Apply Model (3)" to_port="unlabelled data"/>
    <connect from_op="Apply Model (3)" from_port="labelled data" to_op="Performance (2)" to_port="labelled data"/>
    <connect from_op="Performance (2)" from_port="performance" to_port="averagable 1"/>
    <portSpacing port="source_model" spacing="0"/>
    <portSpacing port="source_test set" spacing="0"/>
    <portSpacing port="source_through 1" spacing="0"/>
    <portSpacing port="sink_averagable 1" spacing="0"/>
    <portSpacing port="sink_averagable 2" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="loop" compatibility="7.2.003" expanded="true" height="82" name="Loop" width="90" x="782" y="34">
    <parameter key="set_iteration_macro" value="true"/>
    <parameter key="macro_name" value="loop_forecasts"/>
    <parameter key="iterations" value="%{horizon}"/>
    <process expanded="true">
    <operator activated="true" class="recall" compatibility="7.2.003" expanded="true" height="68" name="Recall" width="90" x="45" y="85">
    <parameter key="name" value="LastRow"/>
    <parameter key="remove_from_store" value="false"/>
    </operator>
    <operator activated="true" class="apply_model" compatibility="7.1.001" expanded="true" height="82" name="Apply Model" width="90" x="246" y="34">
    <list key="application_parameters"/>
    </operator>
    <operator activated="true" class="generate_attributes" compatibility="7.2.003" expanded="true" height="82" name="Generate Attributes" width="90" x="380" y="34">
    <list key="function_descriptions">
    <parameter key="Date" value="date_add(Date,eval(%{loop_forecasts}),DATE_UNIT_DAY)"/>
    </list>
    </operator>
    <operator activated="true" class="set_role" compatibility="5.3.013" expanded="true" height="82" name="Set Role (2)" width="90" x="514" y="34">
    <parameter key="attribute_name" value="prediction(label)"/>
    <list key="set_additional_roles"/>
    </operator>
    <operator activated="true" class="select_attributes" compatibility="7.2.003" expanded="true" height="82" name="Select Attributes (3)" width="90" x="648" y="34">
    <parameter key="attribute_filter_type" value="single"/>
    <parameter key="attribute" value="prediction(label)"/>
    </operator>
    <operator activated="true" class="replace" compatibility="7.2.003" expanded="true" height="82" name="Replace" width="90" x="782" y="34">
    <parameter key="replace_what" value="Close"/>
    <parameter key="replace_by" value="$1-"/>
    </operator>
    <operator activated="true" class="materialize_data" compatibility="7.2.003" expanded="true" height="82" name="Materialize Data (2)" width="90" x="916" y="34"/>
    <connect from_port="input 1" to_op="Apply Model" to_port="model"/>
    <connect from_op="Recall" from_port="result" to_op="Apply Model" to_port="unlabelled data"/>
    <connect from_op="Apply Model" from_port="labelled data" to_op="Generate Attributes" to_port="example set input"/>
    <connect from_op="Generate Attributes" from_port="example set output" to_op="Set Role (2)" to_port="example set input"/>
    <connect from_op="Set Role (2)" from_port="example set output" to_op="Select Attributes (3)" to_port="example set input"/>
    <connect from_op="Select Attributes (3)" from_port="example set output" to_op="Replace" to_port="example set input"/>
    <connect from_op="Replace" from_port="example set output" to_op="Materialize Data (2)" to_port="example set input"/>
    <connect from_op="Materialize Data (2)" from_port="example set output" to_port="output 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="source_input 2" spacing="0"/>
    <portSpacing port="sink_output 1" spacing="0"/>
    <portSpacing port="sink_output 2" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="append" compatibility="7.2.003" expanded="true" height="82" name="Append" width="90" x="916" y="34"/>
    <connect from_op="Yahoo Historical Stock Data" from_port="example set" to_op="Set Role" to_port="example set input"/>
    <connect from_op="Set Role" from_port="example set output" to_op="Rename" to_port="example set input"/>
    <connect from_op="Rename" 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_op="Filter Examples" to_port="example set input"/>
    <connect from_op="Filter Examples" from_port="example set output" to_op="Windowing" to_port="example set input"/>
    <connect from_op="Windowing" from_port="example set output" to_op="Validation (2)" to_port="training"/>
    <connect from_op="Windowing" from_port="original" to_op="Windowing (2)" to_port="example set input"/>
    <connect from_op="Windowing (2)" from_port="example set output" to_op="Extract Macro" to_port="example set"/>
    <connect from_op="Extract Macro" from_port="example set" to_op="Generate Macro" to_port="through 1"/>
    <connect from_op="Generate Macro" from_port="through 1" to_op="Filter Example Range" to_port="example set input"/>
    <connect from_op="Filter Example Range" from_port="example set output" to_op="Remember" to_port="store"/>
    <connect from_op="Validation (2)" from_port="model" to_op="Loop" to_port="input 1"/>
    <connect from_op="Validation (2)" from_port="averagable 1" to_port="result 2"/>
    <connect from_op="Loop" from_port="output 1" to_op="Append" to_port="example set 1"/>
    <connect from_op="Append" from_port="merged set" to_port="result 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="231"/>
    <portSpacing port="sink_result 3" spacing="0"/>
    </process>
    </operator>
    </process>
Sign In or Register to comment.