[Solved] Shift all examples in an attribute by one

qwertzqwertz Member Posts: 130  Maven
edited November 2018 in Help
Dear all,

I'm looking for a way to create a copy of the attributes which is shifted by one example compared to the original.

Original:
att1 att2
10 50
20 100
30 150

Expexted result:
att1 att1_shifted att2 att2_shifted
10 20 50 100
20 30 100 150
30 150


I tried with the "loop" and "macro" operators but until now I found no solution for this.
I'm always struggiling with these two parameters  :(



Cheers
Sachs

Answers

  • qwertzqwertz Member Posts: 130  Maven


    Ok, here is what I found out so far. Not quite yet what I was looking for but maybe this could be an inspiration for all the brains out there...

    Best regards
    Sachs

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.2.003">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.2.003" expanded="true" name="Process">
        <process expanded="true" height="410" width="701">
          <operator activated="true" class="generate_data" compatibility="5.2.003" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30"/>
          <operator activated="true" class="extract_macro" compatibility="5.2.003" expanded="true" height="60" name="Extract Macro (2)" width="90" x="179" y="30">
            <parameter key="macro" value="no"/>
          </operator>
          <operator activated="true" class="generate_macro" compatibility="5.2.003" expanded="true" height="76" name="Generate Macro (2)" width="90" x="313" y="30">
            <list key="function_descriptions">
              <parameter key="no" value="%{no}-1"/>
            </list>
          </operator>
          <operator activated="true" class="loop" compatibility="5.2.003" expanded="true" height="76" name="Loop" width="90" x="447" y="30">
            <parameter key="set_iteration_macro" value="true"/>
            <parameter key="iterations" value="%{no}"/>
            <process expanded="true" height="428" width="652">
              <operator activated="true" class="generate_macro" compatibility="5.2.003" expanded="true" height="76" name="Generate Macro" width="90" x="45" y="30">
                <list key="function_descriptions">
                  <parameter key="row" value="%{iteration}+1"/>
                </list>
              </operator>
              <operator activated="true" class="filter_example_range" compatibility="5.2.003" expanded="true" height="76" name="Filter Example Range" width="90" x="179" y="30">
                <parameter key="first_example" value="%{row}"/>
                <parameter key="last_example" value="%{row}"/>
              </operator>
              <operator activated="true" class="extract_macro" compatibility="5.2.003" expanded="true" height="60" name="Extract Macro" width="90" x="313" y="30">
                <parameter key="macro" value="datavalue"/>
                <parameter key="macro_type" value="data_value"/>
                <parameter key="attribute_name" value="label"/>
                <parameter key="example_index" value="1"/>
              </operator>
              <operator activated="true" class="generate_attributes" compatibility="5.2.003" expanded="true" height="76" name="Generate Attributes" width="90" x="447" y="30">
                <list key="function_descriptions">
                  <parameter key="new" value="%{datavalue}"/>
                </list>
              </operator>
              <connect from_port="input 1" 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="Extract Macro" to_port="example set"/>
              <connect from_op="Extract Macro" from_port="example set" to_op="Generate Attributes" to_port="example set input"/>
              <connect from_op="Generate Attributes" 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="5.2.003" expanded="true" height="76" name="Append" width="90" x="581" y="30"/>
          <connect from_op="Generate Data" from_port="output" to_op="Extract Macro (2)" to_port="example set"/>
          <connect from_op="Extract Macro (2)" from_port="example set" to_op="Generate Macro (2)" to_port="through 1"/>
          <connect from_op="Generate Macro (2)" from_port="through 1" to_op="Loop" to_port="input 1"/>
          <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="0"/>
        </process>
      </operator>
    </process>
  • MariusHelfMariusHelf RapidMiner Certified Expert, Member Posts: 1,869   Unicorn
    Hey, you can do it with one single operator: try Windowing from the Series extension.

    Best,
      Marius
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.2.009">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.2.009" expanded="true" name="Process">
        <process expanded="true" height="534" width="580">
          <operator activated="true" class="generate_nominal_data" compatibility="5.2.009" expanded="true" height="60" name="Generate Nominal Data" width="90" x="45" y="30">
            <parameter key="number_of_attributes" value="1"/>
          </operator>
          <operator activated="true" class="series:windowing" compatibility="5.2.000" expanded="true" height="76" name="Windowing" width="90" x="179" y="30">
            <parameter key="window_size" value="2"/>
          </operator>
          <connect from_op="Generate Nominal Data" from_port="output" to_op="Windowing" to_port="example set input"/>
          <connect from_op="Windowing" 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>
  • qwertzqwertz Member Posts: 130  Maven


    Thank you  :)
Sign In or Register to comment.