Options

"Loop

HelixHelix Member Posts: 1 Contributor I
edited May 2019 in Help
Hi All,

I would like to run 10 replicates of 10-fold cross validation.

The loop & average operator will perform 10 iterations but will the XValidation operator perform 10 independent splitting & stratification procedures? Because it is useless if my workflow loop 10 times with the same subsets of cross validation.

What is the different with or without local random seed for XValidation operator? I would like to reproduce the results but I;m curious since I got the same results without using local random seed after few runs of the workflow.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.1.006">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="5.1.006" expanded="true" name="Process">
    <process expanded="true" height="640" width="614">
      <operator activated="true" class="retrieve" compatibility="5.1.006" expanded="true" height="60" name="Retrieve" width="90" x="45" y="30">
        <parameter key="repository_entry" value="//Samples/data/Iris"/>
      </operator>
      <operator activated="true" class="normalize" compatibility="5.1.006" expanded="true" height="94" name="Normalize" width="90" x="179" y="30">
        <parameter key="method" value="range transformation"/>
        <parameter key="min" value="-1.0"/>
      </operator>
      <operator activated="true" class="optimize_parameters_grid" compatibility="5.1.006" expanded="true" height="112" name="Optimize Parameters (Grid)" width="90" x="313" y="30">
        <list key="parameters">
          <parameter key="SVM.C" value="[0.2;20000;10;linear]"/>
          <parameter key="SVM.gamma" value="[2E-15;2E-3;10;linear]"/>
        </list>
        <process expanded="true" height="623" width="692">
          <operator activated="true" class="loop_and_average" compatibility="5.1.006" expanded="true" height="76" name="Loop and Average" width="90" x="112" y="30">
            <process expanded="true" height="622" width="692">
              <operator activated="true" class="x_validation" compatibility="5.1.006" expanded="true" height="112" name="Validation" width="90" x="179" y="30">
                <description>A cross-validation evaluating a decision tree model.</description>
                <parameter key="local_random_seed" value="197"/>
                <process expanded="true" height="622" width="330">
                  <operator activated="true" class="support_vector_machine_libsvm" compatibility="5.1.006" expanded="true" height="76" name="SVM" width="90" x="120" y="30">
                    <list key="class_weights"/>
                  </operator>
                  <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" height="622" width="330">
                  <operator activated="true" class="apply_model" compatibility="5.1.006" expanded="true" height="76" name="Apply Model" width="90" x="45" y="30">
                    <list key="application_parameters"/>
                  </operator>
                  <operator activated="true" class="performance" compatibility="5.1.006" expanded="true" height="76" name="Performance" width="90" x="187" y="30"/>
                  <connect from_port="model" to_op="Apply Model" to_port="model"/>
                  <connect from_port="test set" to_op="Apply Model" to_port="unlabelled data"/>
                  <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="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="5.1.006" expanded="true" height="76" name="Log" width="90" x="313" y="30">
                <list key="log">
                  <parameter key="C" value="operator.SVM.parameter.C"/>
                  <parameter key="Gamma" value="operator.SVM.parameter.gamma"/>
                  <parameter key="Performance" value="operator.Performance.value.performance"/>
                </list>
              </operator>
              <connect from_port="in 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="averagable 1"/>
              <portSpacing port="source_in 1" spacing="0"/>
              <portSpacing port="source_in 2" spacing="0"/>
              <portSpacing port="sink_averagable 1" spacing="0"/>
              <portSpacing port="sink_averagable 2" spacing="0"/>
            </process>
          </operator>
          <connect from_port="input 1" to_op="Loop and Average" to_port="in 1"/>
          <connect from_op="Loop and Average" from_port="averagable 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"/>
          <portSpacing port="sink_result 2" spacing="0"/>
        </process>
      </operator>
      <connect from_op="Retrieve" from_port="output" to_op="Normalize" to_port="example set input"/>
      <connect from_op="Normalize" from_port="example set output" to_op="Optimize Parameters (Grid)" to_port="input 1"/>
      <connect from_op="Optimize Parameters (Grid)" from_port="performance" to_port="result 1"/>
      <connect from_op="Optimize Parameters (Grid)" from_port="parameter" to_port="result 2"/>
      <connect from_op="Optimize Parameters (Grid)" from_port="result 1" to_port="result 3"/>
      <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"/>
      <portSpacing port="sink_result 4" spacing="0"/>
    </process>
  </operator>
</process>

Answers

  • Options
    IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder
    Hi Helix,

    everything is fine with your process. Indeed, in each of the 10 iterations a different splitting will be used as long as you don't define a local random seed. In this case, all iterations would be the same which can easily be seen if you place a breakpoint after the Loop&Average for a fixed local random seed: the variance is 0 then. I have attached the demo process for this below.

    However, if you don't use a local random seed for the cross validation, each iteration will produce a different split just as desired. It is also completely correct that repeated executions of the same process will deliver exactly the same result. The reason for that is that there is a global random number generator which is used in all cases where not a local random number generator is used (by specifying the local seed). This makes the executions reproducible.

    If you want to get different results for each run, you could change the global random seed which is a parameter of the process itself (just click on the white area of the process view when you are in the top level of the process, there will be a parameter "random seed". If you want to use a different seed for each run, you could even set this parameter to -1. However, I recommend to stick to the default settings here.

    Cheers,
    Ingo

    Here is the process with local random seed and breakpoint (zero variance - hence don't use that for your real evaluation...):

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.1.008">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.1.008" expanded="true" name="Process">
        <process expanded="true" height="640" width="614">
          <operator activated="true" class="retrieve" compatibility="5.1.008" expanded="true" height="60" name="Retrieve" width="90" x="45" y="30">
            <parameter key="repository_entry" value="//Samples/data/Iris"/>
          </operator>
          <operator activated="true" class="normalize" compatibility="5.1.008" expanded="true" height="94" name="Normalize" width="90" x="179" y="30">
            <parameter key="method" value="range transformation"/>
            <parameter key="min" value="-1.0"/>
          </operator>
          <operator activated="true" class="optimize_parameters_grid" compatibility="5.1.008" expanded="true" height="112" name="Optimize Parameters (Grid)" width="90" x="313" y="30">
            <list key="parameters">
              <parameter key="SVM.C" value="[0.2;20000;10;linear]"/>
              <parameter key="SVM.gamma" value="[2E-15;2E-3;10;linear]"/>
            </list>
            <process expanded="true" height="623" width="692">
              <operator activated="true" breakpoints="after" class="loop_and_average" compatibility="5.1.008" expanded="true" height="76" name="Loop and Average" width="90" x="112" y="30">
                <process expanded="true" height="622" width="692">
                  <operator activated="true" class="x_validation" compatibility="5.1.008" expanded="true" height="112" name="Validation" width="90" x="112" y="30">
                    <description>A cross-validation evaluating a decision tree model.</description>
                    <parameter key="use_local_random_seed" value="true"/>
                    <parameter key="local_random_seed" value="197"/>
                    <process expanded="true" height="622" width="330">
                      <operator activated="true" class="support_vector_machine_libsvm" compatibility="5.1.008" expanded="true" height="76" name="SVM" width="90" x="120" y="30">
                        <parameter key="gamma" value="2.0E-15"/>
                        <parameter key="C" value="0.2"/>
                        <list key="class_weights"/>
                      </operator>
                      <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" height="622" width="330">
                      <operator activated="true" class="apply_model" compatibility="5.1.008" expanded="true" height="76" name="Apply Model" width="90" x="45" y="30">
                        <list key="application_parameters"/>
                      </operator>
                      <operator activated="true" class="performance" compatibility="5.1.008" expanded="true" height="76" name="Performance" width="90" x="187" y="30"/>
                      <connect from_port="model" to_op="Apply Model" to_port="model"/>
                      <connect from_port="test set" to_op="Apply Model" to_port="unlabelled data"/>
                      <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="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="5.1.008" expanded="true" height="76" name="Log" width="90" x="313" y="30">
                    <list key="log">
                      <parameter key="C" value="operator.SVM.parameter.C"/>
                      <parameter key="Gamma" value="operator.SVM.parameter.gamma"/>
                      <parameter key="Performance" value="operator.Performance.value.performance"/>
                    </list>
                  </operator>
                  <connect from_port="in 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="averagable 1"/>
                  <portSpacing port="source_in 1" spacing="0"/>
                  <portSpacing port="source_in 2" spacing="0"/>
                  <portSpacing port="sink_averagable 1" spacing="0"/>
                  <portSpacing port="sink_averagable 2" spacing="0"/>
                </process>
              </operator>
              <connect from_port="input 1" to_op="Loop and Average" to_port="in 1"/>
              <connect from_op="Loop and Average" from_port="averagable 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"/>
              <portSpacing port="sink_result 2" spacing="0"/>
            </process>
          </operator>
          <connect from_op="Retrieve" from_port="output" to_op="Normalize" to_port="example set input"/>
          <connect from_op="Normalize" from_port="example set output" to_op="Optimize Parameters (Grid)" to_port="input 1"/>
          <connect from_op="Optimize Parameters (Grid)" from_port="performance" to_port="result 1"/>
          <connect from_op="Optimize Parameters (Grid)" from_port="parameter" to_port="result 2"/>
          <connect from_op="Optimize Parameters (Grid)" from_port="result 1" to_port="result 3"/>
          <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"/>
          <portSpacing port="sink_result 4" spacing="0"/>
        </process>
      </operator>
    </process>
Sign In or Register to comment.