"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.



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


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

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

 The resulting process looks like thisToData.png




  • Options
    awchisholmawchisholm RapidMiner Certified Expert, Member Posts: 458 Unicorn

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

  • Options
    BalazsBaranyBalazsBarany Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert Posts: 955 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.

Sign In or Register to comment.