"Converting weights - read weights operator"

schillsschills Member Posts: 16  Maven
edited May 23 in Help
HI

How do I convert my output from my model (in which I have produced optimised weights for my attributes shown in the results page) into an attributes_weights_file (*.wgt) so I am able to use the "read weights" operator to import these weights and apply them to a new set of data ??

Thanks
Schills
Tagged:

Answers

  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,529   Unicorn
    Hi,
    you can simply store and retrieve weights as every other object in RapidMiner. You don't need to use read or write weights at all.
    You can apply weights on a dataset by using "scale by Weights". See the following example process:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.1.002">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.1.002" expanded="true" name="Process">
        <parameter key="parallelize_main_process" value="true"/>
        <process expanded="true" height="633" width="547">
          <operator activated="true" class="generate_data" compatibility="5.1.002" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30">
            <parameter key="target_function" value="polynomial classification"/>
          </operator>
          <operator activated="true" class="add_noise" compatibility="5.1.002" expanded="true" height="94" name="Add Noise" width="90" x="180" y="30">
            <list key="noise"/>
          </operator>
          <operator activated="true" class="x_validation" compatibility="5.0.000" expanded="true" height="112" name="Validation" width="90" x="447" y="30">
            <description>A cross-validation evaluating a decision tree model.</description>
            <process expanded="true" height="654" width="466">
              <operator activated="true" breakpoints="after" class="weight_by_relief" compatibility="5.1.002" expanded="true" height="76" name="Weight by Relief" width="90" x="45" y="30"/>
              <operator activated="true" class="multiply" compatibility="5.1.002" expanded="true" height="94" name="Multiply" width="90" x="45" y="210"/>
              <operator activated="true" class="scale_by_weights" compatibility="5.1.002" expanded="true" height="76" name="Scale by Weights" width="90" x="179" y="75"/>
              <operator activated="true" class="decision_tree" compatibility="5.0.000" expanded="true" height="76" name="Decision Tree" width="90" x="313" y="30"/>
              <connect from_port="training" to_op="Weight by Relief" to_port="example set"/>
              <connect from_op="Weight by Relief" from_port="weights" to_op="Multiply" to_port="input"/>
              <connect from_op="Weight by Relief" from_port="example set" to_op="Scale by Weights" to_port="example set"/>
              <connect from_op="Multiply" from_port="output 1" to_op="Scale by Weights" to_port="weights"/>
              <connect from_op="Multiply" from_port="output 2" to_port="through 1"/>
              <connect from_op="Scale by Weights" from_port="example set" to_op="Decision Tree" to_port="training set"/>
              <connect from_op="Decision Tree" from_port="model" to_port="model"/>
              <portSpacing port="source_training" spacing="0"/>
              <portSpacing port="sink_model" spacing="0"/>
              <portSpacing port="sink_through 1" spacing="0"/>
              <portSpacing port="sink_through 2" spacing="0"/>
            </process>
            <process expanded="true" height="654" width="476">
              <operator activated="true" class="scale_by_weights" compatibility="5.1.002" expanded="true" height="76" name="Scale by Weights (2)" width="90" x="45" y="75"/>
              <operator activated="true" class="apply_model" compatibility="5.0.000" expanded="true" height="76" name="Apply Model" width="90" x="179" y="30">
                <list key="application_parameters"/>
              </operator>
              <operator activated="true" class="performance" compatibility="5.0.000" expanded="true" height="76" name="Performance" width="90" x="376" y="30"/>
              <connect from_port="model" to_op="Apply Model" to_port="model"/>
              <connect from_port="test set" to_op="Scale by Weights (2)" to_port="example set"/>
              <connect from_port="through 1" to_op="Scale by Weights (2)" to_port="weights"/>
              <connect from_op="Scale by Weights (2)" from_port="example set" to_op="Apply Model" to_port="unlabelled data"/>
              <connect from_op="Apply Model" from_port="labelled data" to_op="Performance" to_port="labelled data"/>
              <connect from_op="Performance" from_port="performance" to_port="averagable 1"/>
              <portSpacing port="source_model" spacing="0"/>
              <portSpacing port="source_test set" spacing="0"/>
              <portSpacing port="source_through 1" spacing="0"/>
              <portSpacing port="source_through 2" spacing="0"/>
              <portSpacing port="sink_averagable 1" spacing="0"/>
              <portSpacing port="sink_averagable 2" spacing="0"/>
            </process>
          </operator>
          <connect from_op="Generate Data" from_port="output" to_op="Add Noise" to_port="example set input"/>
          <connect from_op="Add Noise" from_port="example set output" to_op="Validation" to_port="training"/>
          <connect from_op="Validation" from_port="averagable 1" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="90"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
        </process>
      </operator>
    </process>
    Greetings,
    Sebastian
  • schillsschills Member Posts: 16  Maven
    Hello

    What do you mean you can retrieve weights as "every other object"? My weights are not generated in rapid miner like in your process below, but are instead stored in an external source (microsoft excel sheet). If I am to retrieve these weights in the normal way, rapid miner thinks it is data and not weights.

    So my question is how do I use weights from an external source and apply it to data within rapid miner by using the "scale by weights operator"? I have tried but when i connect my weights data into the weights input port on the scale by weights operator, it wont work because the data (weights) are not recognised as weights....
  • awchisholmawchisholm RapidMiner Certified Expert, Member Posts: 458   Unicorn
    Hello,

    You could use a rather cludgy approach with the "weight by user specification" operator. I made a quick and dirty example that takes an example set (that could be external) and makes a weights object from it.

    regards

    Andrew
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.1.002">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.1.002" expanded="true" name="Process">
        <process expanded="true" height="550" width="955">
          <operator activated="true" class="generate_data" compatibility="5.1.002" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30">
            <parameter key="number_examples" value="1"/>
            <parameter key="attributes_lower_bound" value="0.0"/>
            <parameter key="attributes_upper_bound" value="1.0"/>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="5.1.002" expanded="true" height="60" name="Extract Macro" width="90" x="45" y="120">
            <parameter key="macro" value="att1Weight"/>
            <parameter key="macro_type" value="statistics"/>
            <parameter key="statistics" value="max"/>
            <parameter key="attribute_name" value="att1"/>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="5.1.002" expanded="true" height="60" name="Extract Macro (2)" width="90" x="45" y="210">
            <parameter key="macro" value="att2Weight"/>
            <parameter key="macro_type" value="statistics"/>
            <parameter key="statistics" value="max"/>
            <parameter key="attribute_name" value="att2"/>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="5.1.002" expanded="true" height="60" name="Extract Macro (3)" width="90" x="45" y="300">
            <parameter key="macro" value="att3Weight"/>
            <parameter key="macro_type" value="statistics"/>
            <parameter key="statistics" value="max"/>
            <parameter key="attribute_name" value="att3"/>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="5.1.002" expanded="true" height="60" name="Extract Macro (4)" width="90" x="45" y="390">
            <parameter key="macro" value="att4Weight"/>
            <parameter key="macro_type" value="statistics"/>
            <parameter key="statistics" value="max"/>
            <parameter key="attribute_name" value="att4"/>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="5.1.002" expanded="true" height="60" name="Extract Macro (5)" width="90" x="45" y="480">
            <parameter key="macro" value="att5Weight"/>
            <parameter key="macro_type" value="statistics"/>
            <parameter key="statistics" value="max"/>
            <parameter key="attribute_name" value="att5"/>
          </operator>
          <operator activated="true" class="weight_by_user_specification" compatibility="5.1.002" expanded="true" height="76" name="Weight by User Specification" width="90" x="246" y="165">
            <parameter key="normalize_weights" value="false"/>
            <list key="name_regex_to_weights">
              <parameter key="att1.*" value="%{att1Weight}"/>
              <parameter key="att2.*" value="%{att2Weight}"/>
              <parameter key="att3.*" value="%{att3Weight}"/>
              <parameter key="att4.*" value="%{att4Weight}"/>
              <parameter key="att5.*" value="%{att5Weight}"/>
            </list>
          </operator>
          <connect from_op="Generate Data" from_port="output" to_op="Extract Macro" to_port="example set"/>
          <connect from_op="Extract Macro" from_port="example set" to_op="Extract Macro (2)" to_port="example set"/>
          <connect from_op="Extract Macro (2)" from_port="example set" to_op="Extract Macro (3)" to_port="example set"/>
          <connect from_op="Extract Macro (3)" from_port="example set" to_op="Extract Macro (4)" to_port="example set"/>
          <connect from_op="Extract Macro (4)" from_port="example set" to_op="Extract Macro (5)" to_port="example set"/>
          <connect from_op="Extract Macro (5)" from_port="example set" to_op="Weight by User Specification" to_port="example set"/>
          <connect from_op="Weight by User Specification" from_port="weights" 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>
  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,529   Unicorn
    Hi all,

    well actually I was very sure this is possible by the Data to Weights operator. But it seems to me: It's quite useless. Please post a feature request in our bug tracker.

    Greetings,
      Sebastian
Sign In or Register to comment.