Options

Problem with Loop Attribute

blatooblatoo Member Posts: 32 Contributor II
edited November 2018 in Help
Hi,

I want to calculate the average value for each attributes in Iris Data Set, so I use the Operator "Loop Attributes" and "Aggregate". But I get the Error Message: "The given example set does not contain an attribute a2."
just like in the picture
image

Why???

My Process is

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="6.1.000">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="6.1.000" expanded="true" name="Process">
    <process expanded="true">
      <operator activated="true" class="retrieve" compatibility="6.1.000" expanded="true" height="60" name="Retrieve Iris" width="90" x="112" y="30">
        <parameter key="repository_entry" value="//Samples/data/Iris"/>
      </operator>
      <operator activated="true" class="loop_attributes" compatibility="6.1.000" expanded="true" height="76" name="Loop Attributes" width="90" x="313" y="30">
        <parameter key="value_type" value="real"/>
        <process expanded="true">
          <operator activated="true" class="aggregate" compatibility="6.1.000" expanded="true" height="76" name="Aggregate" width="90" x="112" y="30">
            <list key="aggregation_attributes">
              <parameter key="%{loop_attribute}" value="average"/>
            </list>
          </operator>
          <connect from_port="example set" to_op="Aggregate" to_port="example set input"/>
          <connect from_op="Aggregate" from_port="example set output" to_port="example set"/>
          <portSpacing port="source_example set" spacing="0"/>
          <portSpacing port="sink_example set" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
        </process>
      </operator>
      <connect from_op="Retrieve Iris" from_port="output" to_op="Loop Attributes" to_port="example set"/>
      <connect from_op="Loop Attributes" from_port="example 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>
Best Reguards!

blatoo

Answers

  • Options
    Marco_BoeckMarco_Boeck Administrator, Moderator, Employee, Member, University Professor Posts: 1,996 RM Engineering
    Hi,

    as a tip: You can set breakpoints before/after an operator to see what is going in/out by right-clicking on it, selecting one of the breakpoint options and then executing the process again.

    You will notice if you add a breakpoint before your "Aggregate" operator that in the first iteration everything works as expected. However the second iteration fails because the input example set is no longer Iris but rather the one you generated via the previous execution of the "Aggregate" operator.
    What happens in your process is:
    You take a dataset and then loop over all its attributes. That means you loop 4 times (because you do not include special attributes in the Loop operator) and the iteration macro will be "a1", "a2", "a3" and finally "a4" when doing so. However when inside the loop, you modified the example set which then becomes the input for the next iteration and that is when it fails.

    I think you had something else in mind when doing this, notice the subtle change of the connected output ports (inside the loop and outside the loop):

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.1.001-SNAPSHOT">
     <context>
       <input/>
       <output/>
       <macros/>
     </context>
     <operator activated="true" class="process" compatibility="6.1.001-SNAPSHOT" expanded="true" name="Process">
       <process expanded="true">
         <operator activated="true" class="retrieve" compatibility="6.1.001-SNAPSHOT" expanded="true" height="60" name="Retrieve Iris" width="90" x="112" y="30">
           <parameter key="repository_entry" value="//Samples/data/Iris"/>
         </operator>
         <operator activated="true" class="loop_attributes" compatibility="6.1.001-SNAPSHOT" expanded="true" height="94" name="Loop Attributes" width="90" x="313" y="30">
           <parameter key="value_type" value="real"/>
           <process expanded="true">
             <operator activated="true" class="aggregate" compatibility="6.1.001-SNAPSHOT" expanded="true" height="76" name="Aggregate" width="90" x="112" y="30">
               <list key="aggregation_attributes">
                 <parameter key="%{loop_attribute}" value="average"/>
               </list>
             </operator>
             <connect from_port="example set" to_op="Aggregate" to_port="example set input"/>
             <connect from_op="Aggregate" from_port="example set output" to_port="result 1"/>
             <portSpacing port="source_example set" spacing="0"/>
             <portSpacing port="sink_example set" spacing="0"/>
             <portSpacing port="sink_result 1" spacing="0"/>
             <portSpacing port="sink_result 2" spacing="0"/>
           </process>
         </operator>
         <connect from_op="Retrieve Iris" from_port="output" to_op="Loop Attributes" to_port="example set"/>
         <connect from_op="Loop Attributes" from_port="result 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"/>
       </process>
     </operator>
    </process>
    Regards,
    Marco
  • Options
    blatooblatoo Member Posts: 32 Contributor II
    Hi Marco,

    vielen Dank für die ausführliche Erklärung! Jetzt funktioniert alles! :D

    Ich habe endlich kapiert, wann benutzt man "res" und wann "exa". :D

    Viele Grüße

    Blatoo
  • Options
    bkrieverbkriever RapidMiner Certified Analyst, Member Posts: 11 Contributor II
    Just as a suggestion you can also use the "default aggregation" option on the Aggregate operator to avoid using loop in the first place.  Selecting "all" for attribute filter type allows you to apply the same function to every attribute.


    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.1.000">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="6.1.000" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="retrieve" compatibility="6.1.000" expanded="true" height="60" name="Retrieve Iris" width="90" x="112" y="30">
            <parameter key="repository_entry" value="//Samples/data/Iris"/>
          </operator>
          <operator activated="true" class="aggregate" compatibility="6.1.000" expanded="true" height="76" name="Aggregate (2)" width="90" x="246" y="30">
            <parameter key="use_default_aggregation" value="true"/>
            <list key="aggregation_attributes"/>
          </operator>
          <connect from_op="Retrieve Iris" from_port="output" to_op="Aggregate (2)" to_port="example set input"/>
          <connect from_op="Aggregate (2)" 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>
  • Options
    blatooblatoo Member Posts: 32 Contributor II
    Hi bkriever,

    thanks very much for the suggestion! It is more easy. :)

    Best Reguards
    Blatoo
Sign In or Register to comment.