Output rules

changuel
changuel New Altair Community Member
edited November 5 in Community Q&A
Hello,
I am using RM in java and I am generating associating rules using FPGrowth. My question is how to parse the resulting rules as in the Gui manner, I wan to get for each rule its support, its confidence, its lift....Is it possible to have the rules in a table as in the gui so as to seperate the premises and the conclusions.
Here is the XML file I used :

<operator name="Root" class="Process" expanded="yes">
    <operator name="CSVExampleSource" class="CSVExampleSource">
        <parameter key="filename" value="...attributes.csv"/>
    </operator>
    <operator name="Nominal2Binominal" class="Nominal2Binominal">
    </operator>
    <operator name="FPGrowth" class="FPGrowth">
        <parameter key="min_support" value="0.1"/>
    </operator>
    <operator name="AssociationRuleGenerator" class="AssociationRuleGenerator">
        <parameter key="min_confidence" value="0.7"/>
    </operator>
</operator>
and here is the java code:

RapidMiner.init(false, true, true, true);

String modelFile = "operator.xml";
File processFile = new File(modelFile);
Process process;

try {
process = RapidMiner.readProcessFile(processFile);
IOContainer input = new IOContainer();
IOContainer output = process.run(input);
.....
With this code, I can see the generated rules in this manner:
[att1= val1] --> [att2= val2] (confidence: 1.000)

And I want to see the values of the support, lift... and not only the confidence.

Thanks in advance.
Tagged:

Answers

  • haddock
    haddock New Altair Community Member
    Hi there,

    The following generates data and makes association rules, which are filed and parsed into an example set. You will get log nasties about unattached files, which you can ignore.
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.0">
      <context>
        <input>
          <location/>
        </input>
        <output>
          <location/>
          <location/>
          <location/>
        </output>
        <macros/>
      </context>
      <operator activated="true" class="process" expanded="true" name="Root">
        <parameter key="logverbosity" value="warning"/>
        <process expanded="true" height="386" width="815">
          <operator activated="true" class="subprocess" expanded="true" height="94" name="Rules to CSV" width="90" x="45" y="75">
            <process expanded="true" height="373" width="897">
              <operator activated="true" class="retrieve" expanded="true" height="60" name="Retrieve" width="90" x="60" y="144">
                <parameter key="repository_entry" value="//Samples/data/Transactions"/>
              </operator>
              <operator activated="true" class="nominal_to_binominal" expanded="true" height="94" name="Nominal2Binominal" width="90" x="246" y="120">
                <parameter key="transform_binominal" value="true"/>
              </operator>
              <operator activated="true" class="fp_growth" expanded="true" height="76" name="FPGrowth" width="90" x="446" y="75"/>
              <operator activated="true" class="create_association_rules" expanded="true" height="60" name="AssociationRuleGenerator" width="90" x="514" y="210"/>
              <operator activated="true" class="write_as_text" expanded="true" height="76" name="Write as Text" width="90" x="680" y="202">
                <parameter key="result_file" value="rules.csv"/>
              </operator>
              <connect from_op="Retrieve" from_port="output" to_op="Nominal2Binominal" to_port="example set input"/>
              <connect from_op="Nominal2Binominal" from_port="example set output" to_op="FPGrowth" to_port="example set"/>
              <connect from_op="FPGrowth" from_port="example set" to_port="out 1"/>
              <connect from_op="FPGrowth" from_port="frequent sets" to_op="AssociationRuleGenerator" to_port="item sets"/>
              <connect from_op="AssociationRuleGenerator" from_port="rules" to_op="Write as Text" to_port="input 1"/>
              <connect from_op="Write as Text" from_port="input 1" to_port="out 2"/>
              <portSpacing port="source_in 1" 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>
          <operator activated="true" class="read_csv" expanded="true" height="60" name="Read CSV" width="90" x="45" y="210">
            <parameter key="file_name" value="rules.csv"/>
            <parameter key="column_separators" value="--&gt;|\("/>
          </operator>
          <operator activated="true" class="rename_by_generic_names" expanded="true" height="76" name="Rename by Generic Names" width="90" x="179" y="210"/>
          <operator activated="true" class="filter_examples" expanded="true" height="76" name="Filter Examples" width="90" x="313" y="210">
            <parameter key="condition_class" value="missing_attributes"/>
            <parameter key="invert_filter" value="true"/>
          </operator>
          <operator activated="true" class="replace" expanded="true" height="76" name="Replace" width="90" x="447" y="210">
            <parameter key="attribute_filter_type" value="single"/>
            <parameter key="attribute" value="att3"/>
            <parameter key="replace_what" value="confidence\:|\)"/>
          </operator>
          <connect from_op="Rules to CSV" from_port="out 2" to_port="result 1"/>
          <connect from_op="Read CSV" from_port="output" to_op="Rename by Generic Names" to_port="example set input"/>
          <connect from_op="Rename by Generic Names" from_port="example set output" to_op="Filter Examples" to_port="example set input"/>
          <connect from_op="Filter Examples" from_port="example set output" to_op="Replace" to_port="example set input"/>
          <connect from_op="Replace" from_port="example set output" 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>
    Have fun!



  • changuel
    changuel New Altair Community Member
    Hello and thank you for your response.
    I tried to run a java process using the XML file that you posted in your reply, the resulting rules are now in a csv file, but still there is only the confidence near each rule. I want to ouput also the support, the lift...
    in your XML file I noticed this :

    <operator activated="true" class="replace" expanded="true" height="76" name="Replace" width="90" x="447" y="210">
            <parameter key="attribute_filter_type" value="single"/>
            <parameter key="attribute" value="att3"/>
            <parameter key="replace_what" value="confidence\:|\)"/>
          </operator>
    What do you mean by att3 and why should I replace the confidence, I want to keep it and to see the other parameters too.
    Is there any way to recup the rules in a java table using the class Rule for example?

    Thank you in advance
  • haddock
    haddock New Altair Community Member
    Hi there,

    If you want to get at the stuff beyond Premise,Conclusion, and Confidence you'll need to delve deeper than the GUI allows, but you can do that with a Groovy script, like this...
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.0">
      <context>
        <input>
          <location/>
        </input>
        <output>
          <location/>
          <location/>
        </output>
        <macros/>
      </context>
      <operator activated="true" class="process" expanded="true" name="Root">
        <parameter key="logverbosity" value="warning"/>
        <process expanded="true" height="217" width="745">
          <operator activated="true" class="retrieve" expanded="true" height="60" name="Retrieve" width="90" x="45" y="30">
            <parameter key="repository_entry" value="//Samples/data/Iris"/>
          </operator>
          <operator activated="true" class="subprocess" expanded="true" height="76" name="Preprocessing" width="90" x="180" y="30">
            <process expanded="true">
              <operator activated="true" class="discretize_by_frequency" expanded="true" name="FrequencyDiscretization">
                <parameter key="number_of_bins" value="5"/>
              </operator>
              <operator activated="true" class="nominal_to_binominal" expanded="true" name="Nominal2Binominal">
                <parameter key="transform_binominal" value="true"/>
              </operator>
              <connect from_port="in 1" to_op="FrequencyDiscretization" to_port="example set input"/>
              <connect from_op="FrequencyDiscretization" from_port="example set output" to_op="Nominal2Binominal" to_port="example set input"/>
              <connect from_op="Nominal2Binominal" from_port="example set output" 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>
          <operator activated="true" class="fp_growth" expanded="true" height="76" name="FPGrowth" width="90" x="313" y="30">
            <parameter key="find_min_number_of_itemsets" value="false"/>
            <parameter key="min_support" value="0.1"/>
          </operator>
          <operator activated="true" class="create_association_rules" expanded="true" height="60" name="AssociationRuleGenerator" width="90" x="313" y="165">
            <parameter key="min_confidence" value="0.7"/>
          </operator>
          <operator activated="true" class="execute_script" expanded="true" height="76" name="Execute Script" width="90" x="581" y="75">
            <parameter key="script" value="import com.rapidminer.tools.Ontology;&#13;&#13;&#10;import com.rapidminer.operator.learner.associations.*;&#13;&#13;&#10;&#13;&#10;AssociationRules rules = input[0];&#13;&#13;&#10;&#10;&#13;// construct attribute set&#13;&#10;Attribute[] attributes= new Attribute[11];&#10;attributes[0] = AttributeFactory.createAttribute(&quot;Premise&quot;, Ontology.STRING);&#13;&#13;&#10;attributes[1] = AttributeFactory.createAttribute(&quot;Premise Items&quot;, Ontology.INTEGER);&#10;attributes[2] = AttributeFactory.createAttribute(&quot;Conclusion&quot;, Ontology.STRING);&#13;&#10;attributes[3] = AttributeFactory.createAttribute(&quot;Conclusion Items&quot;, Ontology.INTEGER);&#13;&#10;attributes[4] = AttributeFactory.createAttribute(&quot;Confidence&quot;, Ontology.REAL);&#13;&#10;attributes[5] = AttributeFactory.createAttribute(&quot;Conviction&quot;, Ontology.REAL);&#13;&#10;attributes[6] = AttributeFactory.createAttribute(&quot;Gain&quot;, Ontology.REAL);&#13;&#10;attributes[7] = AttributeFactory.createAttribute(&quot;Laplace&quot;, Ontology.REAL);&#13;&#13;&#10;attributes[8] = AttributeFactory.createAttribute(&quot;Lift&quot;, Ontology.REAL);&#13;&#10;attributes[9] = AttributeFactory.createAttribute(&quot;Ps&quot;, Ontology.REAL);&#10;&#13;&#13;attributes[10] = AttributeFactory.createAttribute(&quot;Total Support&quot;, Ontology.REAL);&#10;&#13;&#13;&#13;&#10;MemoryExampleTable table = new MemoryExampleTable(attributes);&#10;DataRowFactory ROW_FACTORY = new DataRowFactory(0);&#13;&#10;&#13;String[] strings= new String[11];&#13;&#10;&#10;for (AssociationRule rule : rules) {&#10;&#9;&#9;// construct example data&#10;        strings[0]=rule.toPremiseString();&#13;&#10;        strings[1]=rule.premise.size().toString();&#13;&#10;        strings[2]=rule.toConclusionString();&#13;&#10;        strings[3]=rule.conclusion.size().toString();&#13;&#10;        strings[4]=rule.getConfidence().toString();&#13;&#10;        strings[5]=rule.getConviction().toString();&#13;&#10;        strings[6]=rule.getGain().toString();&#13;&#10;        strings[7]=rule.getLaplace().toString();&#13;&#10;        strings[8]=rule.getLift().toString();&#13;&#10;&#13;        strings[9]=rule.getPs().toString();&#13;&#10;        strings[10]=rule.getTotalSupport().toString();&#13;&#13;&#10;        // make and add row&#13;&#10;        DataRow row = ROW_FACTORY.create(strings, attributes); &#13;&#10;        table.addDataRow(row);&#9;&#10;&#9;&#9;}&#10;&#13;&#10;ExampleSet exampleSet = table.createExampleSet();&#10;return exampleSet;&#10;"/>
          </operator>
          <connect from_op="Retrieve" from_port="output" to_op="Preprocessing" to_port="in 1"/>
          <connect from_op="Preprocessing" from_port="out 1" to_op="FPGrowth" to_port="example set"/>
          <connect from_op="FPGrowth" from_port="frequent sets" to_op="AssociationRuleGenerator" to_port="item sets"/>
          <connect from_op="AssociationRuleGenerator" from_port="rules" to_op="Execute Script" to_port="input 1"/>
          <connect from_op="Execute Script" from_port="output 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>