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

Accessing Name of Collection Items

divot_powelldivot_powell Member Posts: 2 Contributor I
edited November 2018 in Help
Hi,

I've been using rapidminer for a bit now, and have finally been stumped with what I would like to do. Any help would be greatly appreciated.

I have a collection of example sets. These example sets have names I have given them such as KNN, NeuralNet etc corresponding to the type of predictor used (Replacing their original name of 'Append (x)'). I am trying to output these results to a csv file, with a seperate file for each example set, and would like to name the files after these names. Is there a way of accessing the name of an example set (or collection item) as a parameter or otherwise for use in a 'Write CSV' block?

So far I have managed to extract each example set from the collection using a 'Loop Collection' block, then taking the input to each iteration and appending it down to a standard example set. I can pump these into a 'Write CSV' block with no problem, but each iteration creates a new file of the same name, overwriting the previous iterations.

Cheers,

Dan

Answers

  • homburghomburg Employee-RapidMiner, Member Posts: 114 RM Data Scientist
    Hi Dan.

    As far as I know it is not possible to access the name of an IO-Object in order to write a certain csv file. But there are other possibilities. You may use LoopParameters to access a collection item and write certain names or use the %{a} macro to write iteration numbers. Both operator constructions can be found in the following process:
    <process version="5.1.009">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.1.009" expanded="true" name="Process">
        <process expanded="true" height="514" width="705">
          <operator activated="true" class="retrieve" compatibility="5.1.009" expanded="true" height="60" name="Retrieve" width="90" x="45" y="30">
            <parameter key="repository_entry" value="//Samples/data/Golf"/>
          </operator>
          <operator activated="true" class="retrieve" compatibility="5.1.009" expanded="true" height="60" name="Retrieve (2)" width="90" x="45" y="120">
            <parameter key="repository_entry" value="//Samples/data/Iris"/>
          </operator>
          <operator activated="true" class="retrieve" compatibility="5.1.009" expanded="true" height="60" name="Retrieve (3)" width="90" x="45" y="210">
            <parameter key="repository_entry" value="//Samples/data/Sonar"/>
          </operator>
          <operator activated="true" class="collect" compatibility="5.1.009" expanded="true" height="112" name="Collect" width="90" x="246" y="75"/>
          <operator activated="true" class="multiply" compatibility="5.1.009" expanded="true" height="94" name="Multiply" width="90" x="380" y="75"/>
          <operator activated="true" class="loop_collection" compatibility="5.1.009" expanded="true" height="60" name="Use Numbers" width="90" x="514" y="120">
            <process expanded="true" height="514" width="737">
              <operator activated="true" class="write_csv" compatibility="5.1.009" expanded="true" height="60" name="Write CSV (2)" width="90" x="112" y="30">
                <parameter key="csv_file" value="output_%{a}.csv"/>
              </operator>
              <connect from_port="single" to_op="Write CSV (2)" to_port="input"/>
              <portSpacing port="source_single" spacing="0"/>
              <portSpacing port="sink_output 1" spacing="0"/>
            </process>
          </operator>
          <operator activated="true" class="loop_parameters" compatibility="5.1.009" expanded="true" height="76" name="Write Names" width="90" x="514" y="30">
            <list key="parameters">
              <parameter key="Select.index" value="[1;3;3;linear]"/>
              <parameter key="Write CSV.csv_file" value="golf.csv,iris.csv,sonar.csv"/>
            </list>
            <parameter key="synchronize" value="true"/>
            <process expanded="true" height="514" width="737">
              <operator activated="true" class="select" compatibility="5.1.009" expanded="true" height="60" name="Select" width="90" x="112" y="30">
                <parameter key="index" value="3"/>
              </operator>
              <operator activated="true" class="write_csv" compatibility="5.1.009" expanded="true" height="60" name="Write CSV" width="90" x="313" y="30">
                <parameter key="csv_file" value="sonar.csv"/>
              </operator>
              <connect from_port="input 1" to_op="Select" to_port="collection"/>
              <connect from_op="Select" from_port="selected" to_op="Write CSV" to_port="input"/>
              <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"/>
            </process>
          </operator>
          <connect from_op="Retrieve" from_port="output" to_op="Collect" to_port="input 1"/>
          <connect from_op="Retrieve (2)" from_port="output" to_op="Collect" to_port="input 2"/>
          <connect from_op="Retrieve (3)" from_port="output" to_op="Collect" to_port="input 3"/>
          <connect from_op="Collect" from_port="collection" to_op="Multiply" to_port="input"/>
          <connect from_op="Multiply" from_port="output 1" to_op="Write Names" to_port="input 1"/>
          <connect from_op="Multiply" from_port="output 2" to_op="Use Numbers" to_port="collection"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
        </process>
      </operator>
    </process>
    For more information about macro definitions please have a look at our wiki:

    http://rapid-i.com/wiki/index.php?title=First_Steps_With_RapidMiner#Parameter_Macros

    Cheers,
        Helge
  • divot_powelldivot_powell Member Posts: 2 Contributor I
    Something like %{a} was just what I was looking for, I can refer back to which model it is now without any problem and each csv is kept seperate. Thanks for the link to that page too, I feel I probably should have found that one earlier...

    Cheers,

    Dan
Sign In or Register to comment.