How can i extract automaticaly ColumnName from Matrix

wawan_betawawan_beta Member Posts: 3 Contributor I
edited November 2018 in Help
Hello, please sorry for my english)

i use  operator  "Loop Attributes"  and in this operators i use operator "Set Macro" and Generate Attributes. I have Matrix that have 0 and 1. I try to change Value in the fields which has 1 and  put there the Column Name. 

in Set Macro i wrote in Macro field "atts" and value field "%{loop_attribute}"
and in Generate Attributes i wrote in attribute name "%{atts}" and in the function expression field "if(%{atts}==1,str(%{atts}),"")"

but it still generate Matrix only with 1, without columnNames.

Please help me)


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.2.008">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="5.2.008" expanded="true" name="Process">
    <process expanded="true" height="867" width="1150">
      <operator activated="false" class="read_excel" compatibility="5.2.008" expanded="true" height="60" name="Read Excel" width="90" x="45" y="30">
        <parameter key="excel_file" value="Y:\Eigene Dateien\RapidMiner\Beispieldaten2.xlsx"/>
        <parameter key="sheet_number" value="2"/>
        <parameter key="imported_cell_range" value="A1:AB142"/>
        <parameter key="first_row_as_names" value="false"/>
        <list key="annotations">
          <parameter key="0" value="Name"/>
        </list>
        <list key="data_set_meta_data_information">
          <parameter key="0" value="Kundenaussage.true.polynominal.attribute"/>
          <parameter key="1" value="Werkstattaussage.true.polynominal.attribute"/>
          <parameter key="2" value="BeanstandungsID.true.integer.attribute"/>
          <parameter key="3" value="Bauteil Werkstatt.true.polynominal.attribute"/>
          <parameter key="4" value="Fehlerart Werkstatt.true.polynominal.attribute"/>
          <parameter key="5" value="Bauteil  Fehlerart Kunde.true.polynominal.attribute"/>
          <parameter key="6" value="Bauteil Kunde.true.polynominal.attribute"/>
          <parameter key="7" value="Fehlerart Kunde.true.polynominal.attribute"/>
          <parameter key="8" value="KA1.true.polynominal.attribute"/>
          <parameter key="9" value="KA2.true.polynominal.attribute"/>
          <parameter key="10" value="KA3.true.polynominal.attribute"/>
          <parameter key="11" value="KA4.true.polynominal.attribute"/>
          <parameter key="12" value="KA5.true.polynominal.attribute"/>
          <parameter key="13" value="KA6.true.polynominal.attribute"/>
          <parameter key="14" value="KA7.true.polynominal.attribute"/>
          <parameter key="15" value="KA8.true.polynominal.attribute"/>
          <parameter key="16" value="KA9.true.polynominal.attribute"/>
          <parameter key="17" value="KA10.true.polynominal.attribute"/>
          <parameter key="18" value="KA11.true.polynominal.attribute"/>
          <parameter key="19" value="KA12.true.polynominal.attribute"/>
          <parameter key="20" value="KA13.false.binominal.attribute"/>
          <parameter key="21" value="KA14.false.binominal.attribute"/>
          <parameter key="22" value="KA15.false.binominal.attribute"/>
          <parameter key="23" value="KA16.false.binominal.attribute"/>
          <parameter key="24" value="KA17.false.binominal.attribute"/>
          <parameter key="25" value="KA18.false.attribute_value.attribute"/>
          <parameter key="26" value="KA19.false.attribute_value.attribute"/>
        </list>
      </operator>
      <operator activated="false" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes" width="90" x="179" y="30">
        <parameter key="attribute_filter_type" value="subset"/>
        <parameter key="attributes" value="Bauteil  Fehlerart Kunde|KA1|KA10|KA11|KA12|KA2|KA3|KA4|KA5|KA6|KA7|KA8|KA9"/>
      </operator>
      <operator activated="false" class="replace_missing_values" compatibility="5.2.008" expanded="true" height="94" name="Replace Missing Values" width="90" x="313" y="30">
        <parameter key="attribute_filter_type" value="subset"/>
        <parameter key="attributes" value="|KA9|KA8|KA7|KA6|KA5|KA17|KA16|KA15|KA14|KA13|KA12|KA11|KA10"/>
        <parameter key="include_special_attributes" value="true"/>
        <parameter key="default" value="none"/>
        <list key="columns"/>
        <parameter key="replenishment_value" value="test"/>
      </operator>
      <operator activated="false" class="text_to_nominal" compatibility="5.2.008" expanded="true" height="76" name="Text to Nominal" width="90" x="447" y="30"/>
      <operator activated="false" class="nominal_to_binominal" compatibility="5.2.008" expanded="true" height="94" name="Nominal to Binominal" width="90" x="581" y="30"/>
      <operator activated="false" class="information_extraction:line_tokenizer" compatibility="1.0.000" expanded="true" height="76" name="LineTokenizer" width="90" x="715" y="30"/>
      <operator activated="false" class="replace_missing_values" compatibility="5.2.008" expanded="true" height="94" name="Replace Missing Values (2)" width="90" x="648" y="210">
        <parameter key="default" value="none"/>
        <list key="columns"/>
        <parameter key="replenishment_value" value="none"/>
      </operator>
      <operator activated="false" class="pivot" compatibility="5.2.008" expanded="true" height="76" name="Pivot" width="90" x="782" y="210">
        <parameter key="group_attribute" value="Kundenaussage"/>
        <parameter key="index_attribute" value="Kundenaussage"/>
        <parameter key="consider_weights" value="false"/>
        <parameter key="weight_aggregation" value="count"/>
        <parameter key="skip_constant_attributes" value="false"/>
        <parameter key="datamanagement" value="boolean_sparse_array"/>
      </operator>
      <operator activated="false" class="text_to_nominal" compatibility="5.2.008" expanded="true" height="76" name="Text to Nominal (3)" width="90" x="916" y="210"/>
      <operator activated="false" class="nominal_to_binominal" compatibility="5.2.008" expanded="true" height="94" name="Nominal to Binominal (2)" width="90" x="1050" y="210"/>
      <operator activated="false" class="map" compatibility="5.2.008" expanded="true" height="76" name="Map" width="90" x="1050" y="345">
        <list key="value_mappings"/>
      </operator>
      <operator activated="true" class="retrieve" compatibility="5.2.008" expanded="true" height="60" name="Retrieve" width="90" x="45" y="210">
        <parameter key="repository_entry" value="//NewLocalRepository/BspDatei"/>
      </operator>
      <operator activated="true" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes (2)" width="90" x="179" y="210">
        <parameter key="attribute_filter_type" value="single"/>
        <parameter key="attribute" value="A"/>
        <parameter key="attributes" value="A|F"/>
      </operator>
      <operator activated="true" class="filter_example_range" compatibility="5.2.008" expanded="true" height="76" name="Filter Example Range" width="90" x="313" y="210">
        <parameter key="first_example" value="2"/>
        <parameter key="last_example" value="142"/>
      </operator>
      <operator activated="true" class="subprocess" compatibility="5.2.008" expanded="true" height="94" name="Subprocess" width="90" x="447" y="210">
        <process expanded="true" height="685" width="955">
          <operator activated="true" class="text:process_document_from_data" compatibility="5.2.004" expanded="true" height="76" name="Process Documents from Data" width="90" x="246" y="30">
            <parameter key="vector_creation" value="Term Frequency"/>
            <parameter key="add_meta_information" value="false"/>
            <parameter key="datamanagement" value="boolean_sparse_array"/>
            <list key="specify_weights"/>
            <process expanded="true" height="671" width="964">
              <operator activated="true" class="text:transform_cases" compatibility="5.2.004" expanded="true" height="60" name="Transform Cases" width="90" x="45" y="30"/>
              <operator activated="true" class="text:filter_stopwords_german" compatibility="5.2.004" expanded="true" height="60" name="Filter Stopwords (German)" width="90" x="179" y="30">
                <parameter key="stop_word_list" value="Sentiment"/>
              </operator>
              <operator activated="true" class="text:tokenize" compatibility="5.2.004" expanded="true" height="60" name="Tokenize" width="90" x="313" y="30">
                <parameter key="language" value="German"/>
              </operator>
              <operator activated="true" class="text:stem_german" compatibility="5.2.004" expanded="true" height="60" name="Stem (German)" width="90" x="447" y="30"/>
              <operator activated="false" class="text:filter_tokens_by_pos" compatibility="5.2.004" expanded="true" height="60" name="Filter Tokens (by POS Tags)" width="90" x="581" y="30">
                <parameter key="language" value="German"/>
              </operator>
              <operator activated="false" class="multiply" compatibility="5.2.008" expanded="true" height="60" name="Multiply" width="90" x="715" y="30"/>
              <operator activated="true" class="text:extract_token_number" compatibility="5.2.004" expanded="true" height="60" name="Extract Token Number" width="90" x="849" y="30"/>
              <connect from_port="document" to_op="Transform Cases" to_port="document"/>
              <connect from_op="Transform Cases" from_port="document" to_op="Filter Stopwords (German)" to_port="document"/>
              <connect from_op="Filter Stopwords (German)" from_port="document" to_op="Tokenize" to_port="document"/>
              <connect from_op="Tokenize" from_port="document" to_op="Stem (German)" to_port="document"/>
              <connect from_op="Stem (German)" from_port="document" to_op="Extract Token Number" to_port="document"/>
              <connect from_op="Extract Token Number" from_port="document" to_port="document 1"/>
              <portSpacing port="source_document" spacing="0"/>
              <portSpacing port="sink_document 1" spacing="0"/>
              <portSpacing port="sink_document 2" spacing="0"/>
            </process>
          </operator>
          <operator activated="true" class="multiply" compatibility="5.2.008" expanded="true" height="94" name="Multiply (2)" width="90" x="380" y="30"/>
          <operator activated="true" class="loop_attributes" compatibility="5.2.008" expanded="true" height="60" name="Loop Attributes" width="90" x="581" y="30">
            <process expanded="true" height="671" width="964">
              <operator activated="false" class="multiply" compatibility="5.2.008" expanded="true" height="60" name="Multiply (3)" width="90" x="246" y="480"/>
              <operator activated="false" class="extract_macro" compatibility="5.2.008" expanded="true" height="60" name="Extract Macro" width="90" x="246" y="255">
                <parameter key="macro" value="atts"/>
              </operator>
              <operator activated="true" class="set_macro" compatibility="5.2.008" expanded="true" height="76" name="Set Macro" width="90" x="313" y="30">
                <parameter key="macro" value="atts"/>
                <parameter key="value" value="%{loop_attribute}"/>
              </operator>
              <operator activated="true" class="generate_attributes" compatibility="5.2.008" expanded="true" height="76" name="Generate Attributes" width="90" x="514" y="30">
                <list key="function_descriptions">
                  <parameter key="%{atts}" value="if(%{atts}==1,str(%{atts}),&quot;&quot;)"/>
                </list>
              </operator>
              <operator activated="false" class="set_data" compatibility="5.2.008" expanded="true" height="76" name="Set Data" width="90" x="648" y="255">
                <parameter key="example_index" value="1"/>
                <parameter key="attribute_name" value="%{atts}"/>
                <parameter key="value" value="333"/>
                <list key="additional_values"/>
              </operator>
              <connect from_port="example set" to_op="Set Macro" to_port="through 1"/>
              <connect from_op="Set Macro" from_port="through 1" to_op="Generate Attributes" to_port="example set input"/>
              <connect from_op="Generate Attributes" from_port="example set output" to_port="example set"/>
              <portSpacing port="source_example set" spacing="0"/>
              <portSpacing port="sink_example set" spacing="0"/>
            </process>
          </operator>
          <operator activated="false" class="text:wordlist_to_data" compatibility="5.2.004" expanded="true" height="76" name="WordList to Data" width="90" x="45" y="435"/>
          <operator activated="false" class="loop_values" compatibility="5.2.008" expanded="true" height="60" name="Loop Values" width="90" x="45" y="525">
            <parameter key="attribute" value="A"/>
            <parameter key="iteration_macro" value="142"/>
            <process expanded="true" height="671" width="950">
              <portSpacing port="source_example set" spacing="0"/>
              <portSpacing port="sink_out 1" spacing="0"/>
            </process>
          </operator>
          <operator activated="false" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="AttributeFilter (2)" width="90" x="514" y="435">
            <parameter key="attribute_filter_type" value="regular_expression"/>
            <parameter key="regular_expression" value=".*true.*"/>
          </operator>
          <operator activated="false" breakpoints="after" class="fp_growth" compatibility="5.2.008" expanded="true" height="76" name="FP-Growth (2)" width="90" x="648" y="435">
            <parameter key="min_number_of_itemsets" value="20"/>
            <parameter key="max_number_of_retries" value="25"/>
            <parameter key="min_support" value="0.15"/>
            <parameter key="max_items" value="5"/>
            <parameter key="must_contain" value="fach"/>
          </operator>
          <operator activated="false" class="create_association_rules" compatibility="5.2.008" expanded="true" height="76" name="AssociationRuleGenerator (3)" width="90" x="782" y="435"/>
          <operator activated="false" class="rename" compatibility="5.2.008" expanded="true" height="76" name="Rename" width="90" x="45" y="210">
            <list key="rename_additional_attributes"/>
          </operator>
          <operator activated="false" class="generate_attributes" compatibility="5.2.008" expanded="true" height="76" name="Generate Attributes (2)" width="90" x="380" y="435">
            <list key="function_descriptions">
              <parameter key="columnName" value="columnName"/>
            </list>
          </operator>
          <connect from_port="in 1" to_op="Process Documents from Data" to_port="example set"/>
          <connect from_op="Process Documents from Data" from_port="example set" to_op="Multiply (2)" to_port="input"/>
          <connect from_op="Multiply (2)" from_port="output 1" to_op="Loop Attributes" to_port="example set"/>
          <connect from_op="Multiply (2)" from_port="output 2" to_port="out 2"/>
          <connect from_op="Loop Attributes" from_port="example set" to_port="out 1"/>
          <connect from_op="FP-Growth (2)" from_port="frequent sets" to_op="AssociationRuleGenerator (3)" to_port="item sets"/>
          <portSpacing port="source_in 1" spacing="0"/>
          <portSpacing port="source_in 2" spacing="0"/>
          <portSpacing port="sink_out 1" spacing="0"/>
          <portSpacing port="sink_out 2" spacing="0"/>
          <portSpacing port="sink_out 3" spacing="0"/>
        </process>
      </operator>
      <connect from_op="Read Excel" from_port="output" to_op="Select Attributes" to_port="example set input"/>
      <connect from_op="Select Attributes" from_port="example set output" to_op="Replace Missing Values" to_port="example set input"/>
      <connect from_op="Replace Missing Values" from_port="original" to_op="Text to Nominal" to_port="example set input"/>
      <connect from_op="Text to Nominal" from_port="example set output" to_op="Nominal to Binominal" to_port="example set input"/>
      <connect from_op="Nominal to Binominal" from_port="example set output" to_op="LineTokenizer" to_port="example set input"/>
      <connect from_op="Replace Missing Values (2)" from_port="example set output" to_op="Pivot" to_port="example set input"/>
      <connect from_op="Pivot" from_port="example set output" to_op="Text to Nominal (3)" to_port="example set input"/>
      <connect from_op="Text to Nominal (3)" from_port="example set output" to_op="Nominal to Binominal (2)" to_port="example set input"/>
      <connect from_op="Retrieve" from_port="output" to_op="Select Attributes (2)" to_port="example set input"/>
      <connect from_op="Select Attributes (2)" from_port="example set output" to_op="Filter Example Range" to_port="example set input"/>
      <connect from_op="Filter Example Range" from_port="example set output" to_op="Subprocess" to_port="in 1"/>
      <connect from_op="Subprocess" from_port="out 1" to_port="result 1"/>
      <connect from_op="Subprocess" from_port="out 2" to_port="result 2"/>
      <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"/>
    </process>
  </operator>
</process>

Answers

  • MariusHelfMariusHelf RapidMiner Certified Expert, Member Posts: 1,869 Unicorn
    Hi sorry, I don't get the point. Are you trying to convert the first row of your input data into column headers? Usually you can do that already during the data import, e.g. by defining the Name annotation for the first row in the Read CSV or Read Excel configuration wizard.

    If you still have problems, please post a short sample of your data and describe your problem more detailed. Also, if you have problems with the import wizard or if I did understand your issue completely wrong, please let me know.

    Best regards,
    Marius
  • wawan_betawawan_beta Member Posts: 3 Contributor I
    i have Table with 1 and 0
            ColumnName1ColumnName2
    Row 1        1              0
    Row2        0              1
    i try to change it to
                    ColumnName1                      ColumnName2
    Row 1        ColumnName1               
    Row2                                                      ColumnName2

    it seem so that i can read the column name, but if i use operator Generate Attributes with funktion: name "%{atts}" and in the function expression field "if(%{atts}==1,str(%{atts}),"")", i became table with 1 and without 0
            ColumnName1ColumnName2
    Row 1        1               
    Row2                        1


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

    You need to put quotes around the macro in the result of the if statement.

    if(%{loop_attribute}==1,"%{loop_attribute}","")
    Here's an example
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.3.000">
     <context>
       <input/>
       <output/>
       <macros/>
     </context>
     <operator activated="true" class="process" compatibility="5.3.000" expanded="true" name="Process">
       <process expanded="true" height="867" width="1150">
         <operator activated="false" class="nominal_to_binominal" compatibility="5.3.000" expanded="true" height="94" name="Nominal to Binominal (2)" width="90" x="1050" y="210"/>
         <operator activated="false" class="map" compatibility="5.3.000" expanded="true" height="76" name="Map" width="90" x="1050" y="345">
           <list key="value_mappings"/>
         </operator>
         <operator activated="true" class="generate_data_user_specification" compatibility="5.3.000" expanded="true" height="60" name="Generate Data by User Specification" width="90" x="45" y="75">
           <list key="attribute_values">
             <parameter key="text" value="&quot;The quick brown fox jumped over the lazy dog&quot;"/>
           </list>
           <list key="set_additional_roles"/>
         </operator>
         <operator activated="true" class="generate_data_user_specification" compatibility="5.3.000" expanded="true" height="60" name="Generate Data by User Specification (2)" width="90" x="45" y="165">
           <list key="attribute_values">
             <parameter key="text" value="&quot;The rain in Spain falls mainly on the plain&quot;"/>
           </list>
           <list key="set_additional_roles"/>
         </operator>
         <operator activated="true" class="append" compatibility="5.3.000" expanded="true" height="94" name="Append" width="90" x="179" y="120"/>
         <operator activated="true" class="nominal_to_text" compatibility="5.3.000" expanded="true" height="76" name="Nominal to Text" width="90" x="313" y="120"/>
         <operator activated="true" class="subprocess" compatibility="5.3.000" expanded="true" height="76" name="Subprocess" width="90" x="447" y="120">
           <process expanded="true" height="685" width="955">
             <operator activated="true" class="text:process_document_from_data" compatibility="5.3.000" expanded="true" height="76" name="Process Documents from Data" width="90" x="179" y="75">
               <parameter key="vector_creation" value="Term Frequency"/>
               <parameter key="add_meta_information" value="false"/>
               <parameter key="datamanagement" value="boolean_sparse_array"/>
               <list key="specify_weights"/>
               <process expanded="true" height="671" width="964">
                 <operator activated="true" class="text:tokenize" compatibility="5.3.000" expanded="true" height="60" name="Tokenize" width="90" x="112" y="30">
                   <parameter key="language" value="German"/>
                 </operator>
                 <operator activated="true" class="text:transform_cases" compatibility="5.3.000" expanded="true" height="60" name="Transform Cases" width="90" x="246" y="30"/>
                 <connect from_port="document" to_op="Tokenize" to_port="document"/>
                 <connect from_op="Tokenize" from_port="document" to_op="Transform Cases" to_port="document"/>
                 <connect from_op="Transform Cases" from_port="document" to_port="document 1"/>
                 <portSpacing port="source_document" spacing="0"/>
                 <portSpacing port="sink_document 1" spacing="0"/>
                 <portSpacing port="sink_document 2" spacing="0"/>
               </process>
             </operator>
             <operator activated="true" class="loop_attributes" compatibility="5.3.000" expanded="true" height="76" name="Loop Attributes" width="90" x="380" y="75">
               <process expanded="true" height="671" width="964">
                 <operator activated="true" class="generate_attributes" compatibility="5.3.000" expanded="true" height="76" name="Generate Attributes" width="90" x="179" y="30">
                   <list key="function_descriptions">
                     <parameter key="%{loop_attribute}" value="if(%{loop_attribute}==1,&quot;%{loop_attribute}&quot;,&quot;&quot;)"/>
                   </list>
                 </operator>
                 <connect 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="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_port="in 1" to_op="Process Documents from Data" to_port="example set"/>
             <connect from_op="Process Documents from Data" from_port="example set" to_op="Loop Attributes" to_port="example set"/>
             <connect from_op="Loop Attributes" from_port="example set" to_port="out 1"/>
             <portSpacing port="source_in 1" spacing="0"/>
             <portSpacing port="source_in 2" spacing="0"/>
             <portSpacing port="sink_out 1" spacing="0"/>
             <portSpacing port="sink_out 2" spacing="0"/>
           </process>
         </operator>
         <connect from_op="Generate Data by User Specification" from_port="output" to_op="Append" to_port="example set 1"/>
         <connect from_op="Generate Data by User Specification (2)" from_port="output" to_op="Append" to_port="example set 2"/>
         <connect from_op="Append" from_port="merged set" to_op="Nominal to Text" to_port="example set input"/>
         <connect from_op="Nominal to Text" from_port="example set output" to_op="Subprocess" to_port="in 1"/>
         <connect from_op="Subprocess" from_port="out 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

    Andrew
  • wawan_betawawan_beta Member Posts: 3 Contributor I
    Thanks for your help, it works now)
Sign In or Register to comment.