RapidMiner 9.8 Beta is now available

Be one of the first to get your hands on the new features. More details and downloads here:

GET RAPIDMINER 9.8 BETA

"Writing Association Rules to Exampleset or file"

bhupendra_patilbhupendra_patil Administrator, Employee, Member Posts: 168  RM Data Scientist
edited June 2019 in Knowledge Base

RapidMiner provides the ability to mine frequent itemsets as well as "Generate Association rules" from frequent item sets. Sometimes there is a need to export the association rules to datasets, files or other formats, but since assosciation rules are not example set, you need to work around to convert it to exampleset to write into other formats.

 

The attached example shows how to do it.

The key thing here is we use the RapidMiner "write" operator. Most objects in RapidMiner are XML's under the hood, and hence we can use the "Read XML" operator to parse the object and convert it to data set. We also utilized the "Import Configuration Wizard" for the read xml to find the right nodes in the XML to parse.

association.png

 

Once we read from XML, we then rename the columns to make it easier for follow on processing.

 

Getting the table via Execute Script

Another option to convert the rules item is to use an Execute Script operator. This operator gets a groovy script to convert the rules to a table.

The script looks like this.

 

 

import com.rapidminer.tools.Ontology;

import com.rapidminer.operator.learner.associations.*;


AssociationRules rules = input[0];



// construct attribute set
Attribute[] attributes= new Attribute[11];
attributes[0] = AttributeFactory.createAttribute("Premise", Ontology.STRING);

attributes[1] = AttributeFactory.createAttribute("Premise Items", Ontology.INTEGER);
attributes[2] = AttributeFactory.createAttribute("Conclusion", Ontology.STRING);
attributes[3] = AttributeFactory.createAttribute("Conclusion Items", Ontology.INTEGER);
attributes[4] = AttributeFactory.createAttribute("Confidence", Ontology.REAL);
attributes[5] = AttributeFactory.createAttribute("Conviction", Ontology.REAL);
attributes[6] = AttributeFactory.createAttribute("Gain", Ontology.REAL);
attributes[7] = AttributeFactory.createAttribute("Laplace", Ontology.REAL);

attributes[8] = AttributeFactory.createAttribute("Lift", Ontology.REAL);
attributes[9] = AttributeFactory.createAttribute("Ps", Ontology.REAL);


attributes[10] = AttributeFactory.createAttribute("Total Support", Ontology.REAL);



MemoryExampleTable table = new MemoryExampleTable(attributes);
DataRowFactory ROW_FACTORY = new DataRowFactory(0);

String[] strings= new String[11];

for (AssociationRule rule : rules) {
// construct example data
strings[0]=rule.toPremiseString();
strings[1]=rule.premise.size().toString();
strings[2]=rule.toConclusionString();
strings[3]=rule.conclusion.size().toString();
strings[4]=rule.getConfidence().toString();
strings[5]=rule.getConviction().toString();
strings[6]=rule.getGain().toString();
strings[7]=rule.getLaplace().toString();
strings[8]=rule.getLift().toString();

strings[9]=rule.getPs().toString();
strings[10]=rule.getTotalSupport().toString();

// make and add row
DataRow row = ROW_FACTORY.create(strings, attributes);
table.addDataRow(row);
}

ExampleSet exampleSet = table.createExampleSet();
return exampleSet;

 The resulting process looks like thisToData.png

 

 

websiteguy

Comments

  • awchisholmawchisholm RapidMiner Certified Expert, Member Posts: 458   Unicorn

    The read XML operator is not licensed in the community version.

  • BalazsBaranyBalazsBarany Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert Posts: 473   Unicorn

    Another approach is using the Reporting extension from the Marketplace.

     

    You include a Generate Report operator in your process, name the report (e. g. Rules) and specify Excel as the output format.

     

    Then you add a Report operator after the Create Association Rules. You enter the name of the Report object (Rules), enter a title, and select the output format in Configure Report. I used "Association Rules" and "Table View". 

     

    The result is a nice Excel table that contains the rules in an easily parsable form.

    rademawebsiteguy
Sign In or Register to comment.