[Solved] Avoid empty clusters in Cluster Model

Unknown
edited November 5 in Community Q&A
Hi ,

I am clustering with means of K-means clustering (fast) , and after that I extract prototypes , but some of the prototypes belongs to empty clusters , so all of their values are missing , how can I remove these instances from my example set (or how can I avoid empty clusters )  ?

Thanks in advance ,

Arian

<?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="640" width="2904">
     <operator activated="true" class="retrieve" compatibility="5.2.008" expanded="true" height="60" name="Retrieve (3)" width="90" x="45" y="255">
       <parameter key="repository_entry" value="descritized_MI_4"/>
     </operator>
     <operator activated="true" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes" width="90" x="246" y="255">
       <parameter key="attribute_filter_type" value="subset"/>
       <parameter key="attributes" value="|id|discharge|admit"/>
       <parameter key="invert_selection" value="true"/>
     </operator>
     <operator activated="true" class="sample_stratified" compatibility="5.2.008" expanded="true" height="76" name="Sample (2)" width="90" x="447" y="255">
       <parameter key="sample" value="relative"/>
       <parameter key="sample_ratio" value="0.01"/>
     </operator>
     <operator activated="true" class="nominal_to_numerical" compatibility="5.2.008" expanded="true" height="94" name="Nominal to Numerical" width="90" x="648" y="120">
       <parameter key="attribute" value="sex"/>
       <list key="comparison_groups"/>
     </operator>
     <operator activated="true" class="normalize" compatibility="5.2.008" expanded="true" height="94" name="Normalize" width="90" x="782" y="120"/>
     <operator activated="true" class="multiply" compatibility="5.2.008" expanded="true" height="94" name="Multiply" width="90" x="1050" y="120"/>
     <operator activated="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples (4)" width="90" x="1251" y="300">
       <parameter key="condition_class" value="attribute_value_filter"/>
       <parameter key="parameter_string" value="event=t"/>
     </operator>
     <operator activated="true" class="extract_macro" compatibility="5.2.008" expanded="true" height="60" name="Extract Macro" width="90" x="1452" y="300">
       <parameter key="macro" value="k"/>
       <parameter key="attribute_name" value="event"/>
     </operator>
     <operator activated="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples" width="90" x="1251" y="30">
       <parameter key="condition_class" value="attribute_value_filter"/>
       <parameter key="parameter_string" value="event=f"/>
     </operator>
     <operator activated="true" class="multiply" compatibility="5.2.008" expanded="true" height="76" name="Multiply (2)" width="90" x="1452" y="165"/>
     <operator activated="true" class="fast_k_means" compatibility="5.2.008" expanded="true" height="76" name="Clustering (3)" width="90" x="1586" y="165">
       <parameter key="k" value="%{k}"/>
     </operator>
     <operator activated="true" class="extract_prototypes" compatibility="5.2.008" expanded="true" height="76" name="Extract Cluster Prototypes" width="90" x="1720" y="165"/>
     <operator activated="true" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes (2)" width="90" x="1921" y="165">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="cluster"/>
       <parameter key="invert_selection" value="true"/>
       <parameter key="include_special_attributes" value="true"/>
     </operator>
     <operator activated="true" class="generate_attributes" compatibility="5.2.008" expanded="true" height="76" name="Generate Attributes" width="90" x="2055" y="165">
       <list key="function_descriptions">
         <parameter key="event" value="&quot;f&quot;"/>
       </list>
     </operator>
     <operator activated="true" class="numerical_to_binominal" compatibility="5.2.008" expanded="true" height="76" name="Numerical to Binominal" width="90" x="2189" y="165">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="event"/>
     </operator>
     <operator activated="true" class="set_role" compatibility="5.2.008" expanded="true" height="76" name="Set Role (2)" width="90" x="2323" y="165">
       <parameter key="name" value="event"/>
       <parameter key="target_role" value="label"/>
       <list key="set_additional_roles"/>
     </operator>
     <operator activated="false" class="shuffle" compatibility="5.2.008" expanded="true" height="76" name="Shuffle" width="90" x="2658" y="30"/>
     <operator activated="true" class="multiply" compatibility="5.2.008" expanded="true" height="94" name="Multiply (3)" width="90" x="2524" y="165"/>
     <operator activated="true" class="append" compatibility="5.2.008" expanded="true" height="94" name="Append" width="90" x="2725" y="345"/>
     <connect from_op="Retrieve (3)" from_port="output" to_op="Select Attributes" to_port="example set input"/>
     <connect from_op="Select Attributes" from_port="example set output" to_op="Sample (2)" to_port="example set input"/>
     <connect from_op="Sample (2)" from_port="example set output" to_op="Nominal to Numerical" to_port="example set input"/>
     <connect from_op="Nominal to Numerical" from_port="example set output" to_op="Normalize" to_port="example set input"/>
     <connect from_op="Normalize" from_port="example set output" to_op="Multiply" to_port="input"/>
     <connect from_op="Multiply" from_port="output 1" to_op="Filter Examples" to_port="example set input"/>
     <connect from_op="Multiply" from_port="output 2" to_op="Filter Examples (4)" to_port="example set input"/>
     <connect from_op="Filter Examples (4)" from_port="example set output" to_op="Extract Macro" to_port="example set"/>
     <connect from_op="Extract Macro" from_port="example set" to_op="Append" to_port="example set 1"/>
     <connect from_op="Filter Examples" from_port="example set output" to_op="Multiply (2)" to_port="input"/>
     <connect from_op="Multiply (2)" from_port="output 1" to_op="Clustering (3)" to_port="example set"/>
     <connect from_op="Clustering (3)" from_port="cluster model" to_op="Extract Cluster Prototypes" to_port="model"/>
     <connect from_op="Extract Cluster Prototypes" from_port="example set" to_op="Select Attributes (2)" to_port="example set input"/>
     <connect from_op="Select Attributes (2)" from_port="example set output" to_op="Generate Attributes" to_port="example set input"/>
     <connect from_op="Generate Attributes" from_port="example set output" to_op="Numerical to Binominal" to_port="example set input"/>
     <connect from_op="Numerical to Binominal" from_port="example set output" to_op="Set Role (2)" to_port="example set input"/>
     <connect from_op="Set Role (2)" from_port="example set output" to_op="Multiply (3)" to_port="input"/>
     <connect from_op="Multiply (3)" from_port="output 1" to_op="Append" to_port="example set 2"/>
     <connect from_op="Multiply (3)" from_port="output 2" 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

  • MariusHelf
    MariusHelf New Altair Community Member
    HI Arian,

    you can use Filter Examples to remove examples which contain missing attributes. Please see the attached process for a sample process.


    Best, Marius
    <?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="416" width="749">
          <operator activated="true" breakpoints="after" class="subprocess" compatibility="5.3.000" expanded="true" height="76" name="Create data with missings" width="90" x="45" y="30">
            <process expanded="true" height="434" width="767">
              <operator activated="true" class="generate_data" compatibility="5.3.000" expanded="true" height="60" name="Generate Data" width="90" x="112" y="30">
                <parameter key="number_examples" value="5"/>
                <parameter key="number_of_attributes" value="2"/>
              </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="112" y="120">
                <list key="attribute_values">
                  <parameter key="att1" value="-1"/>
                  <parameter key="att2" value="-1"/>
                  <parameter key="label" value="-1"/>
                </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="312" y="46"/>
              <operator activated="true" class="declare_missing_value" compatibility="5.3.000" expanded="true" height="76" name="Declare Missing Value" width="90" x="447" y="75">
                <parameter key="numeric_value" value="-1.0"/>
              </operator>
              <connect from_op="Generate Data" from_port="output" to_op="Append" to_port="example set 1"/>
              <connect from_op="Generate Data by User Specification" from_port="output" to_op="Append" to_port="example set 2"/>
              <connect from_op="Append" from_port="merged set" to_op="Declare Missing Value" to_port="example set input"/>
              <connect from_op="Declare Missing Value" from_port="example set output" to_port="out 1"/>
              <portSpacing port="source_in 1" spacing="0"/>
              <portSpacing port="sink_out 1" spacing="0"/>
              <portSpacing port="sink_out 2" spacing="0"/>
            </process>
          </operator>
          <operator activated="true" class="filter_examples" compatibility="5.3.000" expanded="true" height="76" name="Filter Examples" width="90" x="179" y="30">
            <parameter key="condition_class" value="no_missing_attributes"/>
          </operator>
          <connect from_op="Create data with missings" from_port="out 1" to_op="Filter Examples" to_port="example set input"/>
          <connect from_op="Filter Examples" from_port="example set output" 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>