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

"[Solved] Loop function"

olioli Member Posts: 6 Contributor II
edited June 2019 in Help
Hi,

I have recently just started looking at this software and it looks really interesting. I am currently looking at the K-NN part of it.

First of all I was trying to process quite a lot of data, but have made it a lot smaller to try and get it to work, but I still have not managed it so I hope someone on here might be able to help me or point me in the right direction.

On the example I have pasted below, I bring in two names (the attribute is called NAME) where I want to predict a rating using the K-NN, it does not have any of my other data in it.

I then produce a loop, the attribute filter type is single, attribute is NAME and have used the default loop_attributes as the iteration macro.

In the loop I then retrieve the full data set that has lots of attributes in it, I link that to the filter and use parameter string NAME=%{loop_attributes} and then link to the K-NN, Apply Model and Performance. I am pretty sure it is ok from and including K-NN as if I put one of the NAME's instead of %{loop_attributes} it works. But if I leave it as NAME=%{loop_attributes} I get an error saying "The example has no examples".

I have tried quite a lot of things and looked at other peoples code, but I can not see what I am doing wrong, any help would be much appreciated.

Thanks,

Oli
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.008">
 <context>
   <input/>
   <output/>
   <macros/>
 </context>
 <operator activated="true" class="process" compatibility="5.3.008" expanded="true" name="">
   <process expanded="true">
     <operator activated="true" class="retrieve" compatibility="5.3.008" expanded="true" height="60" name="Retrieve Names3 (2)" width="90" x="45" y="120">
       <parameter key="repository_entry" value="data/Names3"/>
     </operator>
     <operator activated="true" class="loop_attributes" compatibility="5.3.008" expanded="true" height="94" name="Loop Attributes" width="90" x="179" y="30">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="NAME"/>
       <parameter key="iteration_macro" value="loop_attributes"/>
       <process expanded="true">
         <operator activated="true" class="retrieve" compatibility="5.3.008" expanded="true" height="60" name="Retrieve data aw" width="90" x="45" y="300">
           <parameter key="repository_entry" value="data/data aw"/>
         </operator>
         <operator activated="true" class="filter_examples" compatibility="5.3.008" expanded="true" height="76" name="Filter Examples" width="90" x="45" y="165">
           <parameter key="condition_class" value="attribute_value_filter"/>
           <parameter key="parameter_string" value="NAME=%{loop_attributes}"/>
         </operator>
         <operator activated="true" class="k_nn" compatibility="5.3.008" expanded="true" height="76" name="k-NN (3)" width="90" x="313" y="75"/>
         <operator activated="true" class="apply_model" compatibility="5.3.008" expanded="true" height="76" name="Apply Model (3)" width="90" x="447" y="75">
           <list key="application_parameters"/>
         </operator>
         <operator activated="true" class="performance" compatibility="5.3.008" expanded="true" height="76" name="Performance (3)" width="90" x="581" y="75"/>
         <connect from_op="Retrieve data aw" from_port="output" to_op="Filter Examples" to_port="example set input"/>
         <connect from_op="Filter Examples" from_port="example set output" to_op="k-NN (3)" to_port="training set"/>
         <connect from_op="k-NN (3)" from_port="model" to_op="Apply Model (3)" to_port="model"/>
         <connect from_op="k-NN (3)" from_port="exampleSet" to_op="Apply Model (3)" to_port="unlabelled data"/>
         <connect from_op="Apply Model (3)" from_port="labelled data" to_op="Performance (3)" to_port="labelled data"/>
         <connect from_op="Performance (3)" from_port="example set" 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 Names3 (2)" 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>

Answers

  • awchisholmawchisholm RapidMiner Certified Expert, Member Posts: 458 Unicorn
    Hello

    If you change the loop operator to be "Loop Values" this will iterate over all the values of the NAME attribute. The "Loop Attributes" operator is looping once for the single attribute name provided (i.e. NAME) and as a consequence no examples match leading to the error you describe.

    regards

    Andrew
  • olioli Member Posts: 6 Contributor II
    Hi Andrew,

    Thank you so much for that, finally got it to work.

    Thanks,

    Oli
Sign In or Register to comment.