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

Forecasting with (linear) Regression - Find best Time Lag of Parameters

christian_langmchristian_langm Member, University Professor Posts: 3 University Professor
edited November 2019 in Help
Dear community,

I am struggling with a (probably) basic question for a model. I have a forecasting model for sales. I use various independent variables such as sales rep visits, incoming call center calls etc. to predict sales with a linear regression. So far no problem. 

Depending on the sales cycle of a business the visit of a sales rep might turn into a sales/revenue one, two or three months later. Now, this is where I am struggling. Basically, I am looking for an algorithm that tells me which time lag (t=-1, t=-2, t=-3 etc.) of a independent variable is best to predict the sales in t=0.

Does anyone have hint for me? 

Many thanks! 

Chris
Tagged:

Best Answer

  • christian_langmchristian_langm Member, University Professor Posts: 3 University Professor
    Solution Accepted
    Many, many thanks for the responses!  :)

    Looking at the correlation matrix to identify different models was also my first idea. However, I am looking for a way to automatically set-up the different models and test them, i.e. without me modeling everyone of them in advance. Imagine if you have 8-10 parameters, different possible time lags and all the combinations. That would not really be convenient. 

    By chance: do you have an example of the sliding window operator for sales forecasting, maybe even with a loop parameter? 

    Best,
    Chris


Answers

  • tftemmetftemme Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, RMResearcher, Member Posts: 164 RM Research
    Hi @christian_langm,

    You can have a look at the autocorrelation between the sales at t=0 and the independent variables to evaluate if there is a high correlation for a specific lag. Also you can setup up a validation scheme by using the Sliding Window Validation operator (or the Forecast Validation operator if you are working with classic forecast models). You built your different models (with different lags) on the training windows and evaluates their prediction performance on the testing windows. Thus you can compare the prediction performance between the different models (with different lags).

    Hopes this helps,
    Best regards,
    Fabian

  • pblack476pblack476 Member Posts: 83 Maven
    Maybe Loop Parameter? Set the Lag with the Lag operator and set that inside Loop Parameter to output all the result and then compare their efficacy?
  • tftemmetftemme Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, RMResearcher, Member Posts: 164 RM Research
    Hi @christian_langm,

    Took me a bit of time to come back to this. Below you can find a demo process to perform such an optimization of different parameters with Sliding Window Validations.
    I used the Gas Prices demo data set inside RapidMiner for demonstration purposes. Note that the execution takes a few moments (for me 20 sec, and I looped only over a few combinations). This is due to the number of iterations in the Sliding Window Validation and the size of the input ExampleSet.
    I looped over the window size of the Windowing operator (which is the 'lag' used in this example). I also combined this with looping over the use_bias parameter of the linear regression to demonstrate how to combine different parameter optimization in the one Optimization operator.

    Hopes this helps,
    Best regards,
    Fabian

    <process version="9.5.001">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.5.001" 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="retrieve" compatibility="9.5.001" expanded="true" height="68" name="Retrieve Prices of Gas Station" width="90" x="112" y="34">
            <parameter key="repository_entry" value="//Samples/Time Series/data sets/Prices of Gas Station"/>
          </operator>
          <operator activated="true" class="time_series:sliding_window_validation" compatibility="9.5.000" expanded="true" height="145" name="Sliding Window Validation" width="90" x="313" y="34">
            <parameter key="has_indices" value="true"/>
            <parameter key="indices_attribute" value="date"/>
            <parameter key="training_window_size" value="7000"/>
            <parameter key="no_overlapping_windows" value="true"/>
            <parameter key="step_size" value="500"/>
            <parameter key="test_window_size" value="1000"/>
            <parameter key="enable_parallel_execution" value="true"/>
            <process expanded="true">
              <operator activated="true" class="concurrency:optimize_parameters_grid" compatibility="9.5.001" expanded="true" height="145" name="Optimize Parameters (Grid)" width="90" x="179" y="34">
                <list key="parameters">
                  <parameter key="Windowing.window_size" value="[12;48;3;linear]"/>
                  <parameter key="Linear Regression.use_bias" value="true,false"/>
                </list>
                <parameter key="error_handling" value="fail on error"/>
                <parameter key="log_performance" value="true"/>
                <parameter key="log_all_criteria" value="false"/>
                <parameter key="synchronize" value="false"/>
                <parameter key="enable_parallel_execution" value="true"/>
                <process expanded="true">
                  <operator activated="true" class="time_series:windowing" compatibility="9.5.000" expanded="true" height="82" name="Windowing" width="90" x="112" y="34">
                    <parameter key="attribute_filter_type" value="all"/>
                    <parameter key="attribute" value=""/>
                    <parameter key="attributes" value=""/>
                    <parameter key="use_except_expression" value="false"/>
                    <parameter key="value_type" value="nominal"/>
                    <parameter key="use_value_type_exception" value="false"/>
                    <parameter key="except_value_type" value="time"/>
                    <parameter key="block_type" value="single_value"/>
                    <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"/>
                    <parameter key="has_indices" value="true"/>
                    <parameter key="indices_attribute" value="date"/>
                    <parameter key="window_size" value="48"/>
                    <parameter key="no_overlapping_windows" value="false"/>
                    <parameter key="step_size" value="1"/>
                    <parameter key="create_horizon_(labels)" value="true"/>
                    <parameter key="horizon_attribute" value="gas price / euro (times 1000)"/>
                    <parameter key="horizon_size" value="1"/>
                    <parameter key="horizon_offset" value="23"/>
                  </operator>
                  <operator activated="true" class="operator_toolbox:get_parameters" compatibility="2.2.000" expanded="true" height="103" name="Get Parameters" width="90" x="313" y="187">
                    <parameter key="operator_name" value="Windowing"/>
                  </operator>
                  <operator activated="true" class="time_series:sliding_window_validation" compatibility="9.5.000" expanded="true" height="145" name="Sliding Window Validation (2)" width="90" x="514" y="34">
                    <parameter key="has_indices" value="false"/>
                    <parameter key="indices_attribute" value=""/>
                    <parameter key="training_window_size" value="4000"/>
                    <parameter key="no_overlapping_windows" value="true"/>
                    <parameter key="step_size" value="500"/>
                    <parameter key="test_window_size" value="500"/>
                    <parameter key="enable_parallel_execution" value="true"/>
                    <process expanded="true">
                      <operator activated="true" class="linear_regression" compatibility="9.5.001" expanded="true" height="103" name="Linear Regression" width="90" x="179" y="34">
                        <parameter key="feature_selection" value="M5 prime"/>
                        <parameter key="alpha" value="0.05"/>
                        <parameter key="max_iterations" value="10"/>
                        <parameter key="forward_alpha" value="0.05"/>
                        <parameter key="backward_alpha" value="0.05"/>
                        <parameter key="eliminate_colinear_features" value="true"/>
                        <parameter key="min_tolerance" value="0.05"/>
                        <parameter key="use_bias" value="true"/>
                        <parameter key="ridge" value="1.0E-8"/>
                      </operator>
                      <connect from_port="training set" to_op="Linear Regression" to_port="training set"/>
                      <connect from_op="Linear Regression" from_port="model" to_port="model"/>
                      <portSpacing port="source_training set" 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="9.5.001" expanded="true" height="82" name="Apply Model" width="90" x="112" y="34">
                        <list key="application_parameters"/>
                        <parameter key="create_view" value="false"/>
                      </operator>
                      <operator activated="true" class="performance_regression" compatibility="9.5.001" expanded="true" height="82" name="Performance" width="90" x="246" y="34">
                        <parameter key="main_criterion" value="first"/>
                        <parameter key="root_mean_squared_error" value="true"/>
                        <parameter key="absolute_error" value="false"/>
                        <parameter key="relative_error" value="false"/>
                        <parameter key="relative_error_lenient" value="false"/>
                        <parameter key="relative_error_strict" value="false"/>
                        <parameter key="normalized_absolute_error" value="false"/>
                        <parameter key="root_relative_squared_error" value="false"/>
                        <parameter key="squared_error" value="false"/>
                        <parameter key="correlation" value="false"/>
                        <parameter key="squared_correlation" value="false"/>
                        <parameter key="prediction_average" value="false"/>
                        <parameter key="spearman_rho" value="false"/>
                        <parameter key="kendall_tau" value="false"/>
                        <parameter key="skip_undefined_labels" value="true"/>
                        <parameter key="use_example_weights" value="true"/>
                      </operator>
                      <connect from_port="test set" to_op="Apply Model" to_port="unlabelled data"/>
                      <connect from_port="model" to_op="Apply Model" to_port="model"/>
                      <connect from_op="Apply Model" from_port="labelled data" to_op="Performance" to_port="labelled data"/>
                      <connect from_op="Performance" from_port="performance" to_port="performance 1"/>
                      <portSpacing port="source_test set" spacing="0"/>
                      <portSpacing port="source_model" spacing="0"/>
                      <portSpacing port="source_through 1" spacing="0"/>
                      <portSpacing port="sink_test set results" spacing="0"/>
                      <portSpacing port="sink_performance 1" spacing="0"/>
                      <portSpacing port="sink_performance 2" spacing="0"/>
                    </process>
                  </operator>
                  <connect from_port="input 1" to_op="Windowing" to_port="example set"/>
                  <connect from_op="Windowing" from_port="windowed example set" to_op="Get Parameters" to_port="through 1"/>
                  <connect from_op="Get Parameters" from_port="parameters" to_port="output 1"/>
                  <connect from_op="Get Parameters" from_port="through 1" to_op="Sliding Window Validation (2)" to_port="example set"/>
                  <connect from_op="Sliding Window Validation (2)" from_port="model" to_port="model"/>
                  <connect from_op="Sliding Window Validation (2)" from_port="performance 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_model" spacing="0"/>
                  <portSpacing port="sink_output 1" spacing="0"/>
                  <portSpacing port="sink_output 2" spacing="0"/>
                </process>
              </operator>
              <connect from_port="training set" to_op="Optimize Parameters (Grid)" to_port="input 1"/>
              <connect from_op="Optimize Parameters (Grid)" from_port="model" to_port="model"/>
              <connect from_op="Optimize Parameters (Grid)" from_port="parameter set" to_port="through 1"/>
              <portSpacing port="source_training set" spacing="0"/>
              <portSpacing port="sink_model" spacing="0"/>
              <portSpacing port="sink_through 1" spacing="0"/>
              <portSpacing port="sink_through 2" spacing="0"/>
            </process>
            <process expanded="true">
              <operator activated="true" class="set_parameters" compatibility="9.5.001" expanded="true" height="124" name="Set Parameters" width="90" x="112" y="85">
                <list key="name_map">
                  <parameter key="Windowing" value="Windowing Testing"/>
                </list>
              </operator>
              <operator activated="true" class="time_series:windowing" compatibility="9.5.000" expanded="true" height="82" name="Windowing Testing" width="90" x="246" y="34">
                <parameter key="attribute_filter_type" value="all"/>
                <parameter key="attribute" value=""/>
                <parameter key="attributes" value=""/>
                <parameter key="use_except_expression" value="false"/>
                <parameter key="value_type" value="nominal"/>
                <parameter key="use_value_type_exception" value="false"/>
                <parameter key="except_value_type" value="time"/>
                <parameter key="block_type" value="single_value"/>
                <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"/>
                <parameter key="has_indices" value="true"/>
                <parameter key="indices_attribute" value="date"/>
                <parameter key="window_size" value="48"/>
                <parameter key="no_overlapping_windows" value="false"/>
                <parameter key="step_size" value="1"/>
                <parameter key="create_horizon_(labels)" value="true"/>
                <parameter key="horizon_attribute" value="gas price / euro (times 1000)"/>
                <parameter key="horizon_size" value="1"/>
                <parameter key="horizon_offset" value="23"/>
              </operator>
              <operator activated="true" class="apply_model" compatibility="9.5.001" expanded="true" height="82" name="Apply Model (2)" width="90" x="380" y="136">
                <list key="application_parameters"/>
                <parameter key="create_view" value="false"/>
              </operator>
              <operator activated="true" class="performance_regression" compatibility="9.5.001" expanded="true" height="82" name="Performance (2)" width="90" x="581" y="34">
                <parameter key="main_criterion" value="first"/>
                <parameter key="root_mean_squared_error" value="true"/>
                <parameter key="absolute_error" value="false"/>
                <parameter key="relative_error" value="false"/>
                <parameter key="relative_error_lenient" value="false"/>
                <parameter key="relative_error_strict" value="false"/>
                <parameter key="normalized_absolute_error" value="false"/>
                <parameter key="root_relative_squared_error" value="false"/>
                <parameter key="squared_error" value="false"/>
                <parameter key="correlation" value="false"/>
                <parameter key="squared_correlation" value="false"/>
                <parameter key="prediction_average" value="false"/>
                <parameter key="spearman_rho" value="false"/>
                <parameter key="kendall_tau" value="false"/>
                <parameter key="skip_undefined_labels" value="true"/>
                <parameter key="use_example_weights" value="true"/>
              </operator>
              <connect from_port="test set" to_op="Set Parameters" to_port="through 1"/>
              <connect from_port="model" to_op="Set Parameters" to_port="through 2"/>
              <connect from_port="through 1" to_op="Set Parameters" to_port="parameter set"/>
              <connect from_op="Set Parameters" from_port="through 1" to_op="Windowing Testing" to_port="example set"/>
              <connect from_op="Set Parameters" from_port="through 2" to_op="Apply Model (2)" to_port="model"/>
              <connect from_op="Windowing Testing" from_port="windowed example set" to_op="Apply Model (2)" to_port="unlabelled data"/>
              <connect from_op="Apply Model (2)" from_port="labelled data" to_op="Performance (2)" to_port="labelled data"/>
              <connect from_op="Performance (2)" from_port="performance" to_port="performance 1"/>
              <portSpacing port="source_test set" spacing="0"/>
              <portSpacing port="source_model" spacing="0"/>
              <portSpacing port="source_through 1" spacing="0"/>
              <portSpacing port="source_through 2" spacing="0"/>
              <portSpacing port="sink_test set results" spacing="0"/>
              <portSpacing port="sink_performance 1" spacing="0"/>
              <portSpacing port="sink_performance 2" spacing="0"/>
            </process>
          </operator>
          <connect from_op="Retrieve Prices of Gas Station" from_port="output" to_op="Sliding Window Validation" to_port="example set"/>
          <connect from_op="Sliding Window Validation" from_port="model" to_port="result 2"/>
          <connect from_op="Sliding Window Validation" from_port="performance 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"/>
          <portSpacing port="sink_result 3" spacing="0"/>
        </process>
      </operator>
    </process>
    



  • christian_langmchristian_langm Member, University Professor Posts: 3 University Professor
    Hi Fabian,

    many thanks. After getting done some other things on my table, I can finally look into it tomorrow.

    Thank you for your effort! I will get back after I tried it out.
Sign In or Register to comment.