SVM - optimizing class weights

danjeharry
danjeharry New Altair Community Member
edited November 5 in Community Q&A
Hey all,

Not sure if this is a feature of rapidminer yet, but I'm using a SVM model and I'd like to try and optimize the class weights for my model (my data is very unbalanced). However, in optimize parameters, it doesn't look like i can select the class weights parameter to optimize. Any suggestions?

Thanks

Answers

  • MariusHelf
    MariusHelf New Altair Community Member
    Hi,

    you have (at least) two options:

    1. use Support Vector Machine instead of Support Vector Machine (libSVM) and optimize the L values.
    2. use macros as in the process below (don't forget to add a X-Validation etc. for evaluation).

    Best, Marius
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.1.011">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.1.011" expanded="true" name="Process">
        <process expanded="true" height="633" width="743">
          <operator activated="true" class="generate_data" compatibility="5.1.011" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30">
            <parameter key="target_function" value="random classification"/>
          </operator>
          <operator activated="true" class="optimize_parameters_grid" compatibility="5.1.011" expanded="true" height="94" name="Optimize Parameters (Grid)" width="90" x="246" y="30">
            <list key="parameters">
              <parameter key="Set Macro.value" value="1,2,3"/>
              <parameter key="Set Macro (2).value" value="1,2,3"/>
            </list>
            <process expanded="true" height="633" width="748">
              <operator activated="true" class="set_macro" compatibility="5.1.011" expanded="true" height="76" name="Set Macro" width="90" x="112" y="30">
                <parameter key="macro" value="w1"/>
                <parameter key="value" value="3"/>
              </operator>
              <operator activated="true" class="set_macro" compatibility="5.1.011" expanded="true" height="76" name="Set Macro (2)" width="90" x="112" y="120">
                <parameter key="macro" value="w2"/>
                <parameter key="value" value="3"/>
              </operator>
              <operator activated="true" class="support_vector_machine_libsvm" compatibility="5.1.011" expanded="true" height="76" name="SVM" width="90" x="313" y="30">
                <list key="class_weights">
                  <parameter key="positive" value="%{w1}"/>
                  <parameter key="negative" value="%{w2}"/>
                </list>
              </operator>
              <operator activated="true" class="apply_model" compatibility="5.1.011" expanded="true" height="76" name="Apply Model" width="90" x="447" y="30">
                <list key="application_parameters"/>
              </operator>
              <operator activated="true" class="performance" compatibility="5.1.011" expanded="true" height="76" name="Performance" width="90" x="581" y="30"/>
              <connect from_port="input 1" to_op="Set Macro" to_port="through 1"/>
              <connect from_op="Set Macro" from_port="through 1" to_op="Set Macro (2)" to_port="through 1"/>
              <connect from_op="Set Macro (2)" from_port="through 1" to_op="SVM" to_port="training set"/>
              <connect from_op="SVM" from_port="model" to_op="Apply Model" to_port="model"/>
              <connect from_op="SVM" from_port="exampleSet" 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="performance"/>
              <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="Generate Data" from_port="output" to_op="Optimize Parameters (Grid)" to_port="input 1"/>
          <connect from_op="Optimize Parameters (Grid)" from_port="performance" to_port="result 1"/>
          <connect from_op="Optimize Parameters (Grid)" from_port="parameter" 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>