Mining Association Rules from Rare Itemsets found by the RP-Growth Algorithm (SPMF documentation)
This example explains how to run the RP-Growth algorithm to extract association rules using the SPMF open-source data mining library.
How to run this example?
- If you are using the graphical interface, (1) choose the “RPGrowth_association_rules” algorithm, (2) select the “contextRP.txt”, (3) set the output file name (e.g. “output.txt”), (4) set minsup to 60%, minraresup to 10%, minconf to 60%, and (5) click “Run algorithm”.
- If you want to execute this example from the command line, the execute this command: java –jar spmf.jar run RPGrowth_association_rules contextRP.txt output.txt 60% 10% 60% in a folder containing spmf.jar and the example input file contextRP.txt
- If you are using the source code version of SPMF, launch the file “ MainTestAllAssociationRules_RPGrowth_saveToFile.java” in the package ca.pfv.SPMF.tests
What is RPGrowth?
RPGrowth is an adaptation of the FPGrowth algorithm for discovering rare itemsets in a transaction database. FPGrowth was proposed by Han et al. (2000) and the adaptation of the FPGrowth to find rare itemsets was proposed by Sidney Tsang, Yun Sing Koh, and Gillian Dobbie (2011). Being modified from the FPGrowth algorithm, it retains the speed, memory efficiency, and the usage of the FP-Tree.
This example describes how to extract rare itemsets with RPGrowth and derive association rules from them. There is another example in the documentation that describe only the first step (extracting rare itemsets).
What is the input of the RPGrowth algorithm for association rule mining?
The input of RPGrowth is a transaction database (aka binary context) and three thresholds:
- minsup (which represents the upper boundary of what is considered “rare”, a value between 0 and 100%),
- minraresup (which represents the lower boundary of what is considered “rare”, a value between 0 and 100%). NOTE: minraresup and minsup represent a range. That being said, minraresup must be lower than minsup.
- minconf: a minimum confidence threshold for deriving association rules from rare itemsets.
A transaction database is a set of transactions. Each transaction is a set of items. For example, consider the following transaction database. It contains 5 transactions (t1, t2, …, t5) and 5 items (1, 2, 3, 4, 5). For example, the first transaction represents the set of items 1, 2, and 4. This database is provided as the file contextRP in the SPMF distribution. It is important to note than an item is not allowed to appear twice in the same transaction and that items are assumed to be sorted by lexicographical order in a transaction.
Transaction id |
Items |
t1 |
{1, 2, 4} |
t2 |
{1, 3} |
t3 |
{1, 2, 3, 5} |
t4 |
{2, 3, 5} |
t5 |
{1, 2, 3, 5} |
What is the output of the RPGrowth algorithm?
RPGrowth is an algorithm for discovering rare itemsets (group of items) occurring infrequently in a transaction database (rare itemsets). A rare itemset is an itemset appearing within the minraresup and minsup range (e.g. minraresup is set to 10% and minsup is set to 60%), where both minraresup and minsup are parameters defined by the user. NOTE: RPGrowth has the requirement that any “rare” itemset of size 2 or greater contain at least one item (itemset of size 1) that was considered “rare”. For example, if RPGrowth is run on the previous transaction database with a minsup of 50% (4 transactions) and minraresup 10% (1 transaction), RPGrowth first extracts the following rare itemsets:
Itemsets |
Support |
{4} |
1 |
{1, 4} |
1 |
{2, 4} |
1 |
{1, 2, 4} |
1 |
Then, association rules are derived from these rare itemsets. To explain what is the result, it is necessary to explain a few definitions.
An association rule X==>Y
is a relationship between two itemsets (sets of items) X and Y such
that the intersection of X and Y is empty. The support of a
rule is the number of transactions that contains X∪Y. The confidence
of a rule is the number of transactions that contains X∪Y
divided by the number of transactions that contain X. The output of association rule mining algorithm is a set of
association rules respecting the user-specified minconf threshold. This means that all rules are output that have a confidence that is no less than 60% in this example. For example, by deriving association rules from the rare itemsets found by RPGrowth we obtains 4 associations rules:
Itemsets |
Support | Confidence |
4 ==> 1 |
1 |
100% |
4 ==> 3 |
1 |
100% |
3 4 ==> 1 |
1 |
100% |
1 4 ==> 3 |
1 |
100% |
| 4 ==> 1 3 | 1 | 100% |
How should I interpret the results?
In the results, each itemset is annotated with its support. The support of an itemset is how many times the itemset appears in the transaction database. For example, the itemset {1, 2, 4} has a support of 1 because it appears in only t1. It is a rare itemset because it falls within the user determined range of what is considered “rare” (and meets previously mentioned constraints).
Input file format:
The input file format used by the RPGrowth is defined as follows. It is a text file. An item is represented by a positive integer. A transaction is a line in the text file. In each line (transaction), items are separated by a single space. It is assumed that all items within a same transaction (line) are sorted according to total order (e.g. ascending order) and that no item can appear twice within the same line.
For example, for the previous example, the input file is defined as follows:
1 2 4
1 3
1 2 3 5
2 3 5
1 2 3 5
Output file format:
The output file format is defined as follows. It is a text file, where each line represents an association rule. On each line, the items of the rule antecedent are first listed. Each item is represented by an integer, followed by a single space. After, that the keyword "==>" appears followed by a space. Then, the items of the rule consequent are listed. Each item is represented by an integer, followed by a single space. Then, the keyword " #SUP: " appears followed by the support of the rule represented by an integer. Then, the keyword " #CONF: " appears followed by the confidence of the rule represented by a double value (a value between 0 and 1, inclusively). For example, here is a few lines from the output file for this example:
4 ==> 1 #SUP: 1 #CONF: 1.0
4 ==> 3 #SUP: 1 #CONF: 1.0
3 4 ==> 1 #SUP: 1 #CONF: 1.0
1 4 ==> 3 #SUP: 1 #CONF: 1.0
4 ==> 1 3 #SUP: 1 #CONF: 1.0
For example, the first line indicates that the association rule {4} --> {1,3} has a support of 1 transaction and a confidence of 100 %. The other lines follow the same format.
Note that if the ARFF format is used as input instead of the default input format, the output format will be the same except that items will be represented by strings instead of integers.
Optional feature: constraints on the size of association rules
Sometimes, there may be just too many association rules, and rules containing many items may not be interesting. Thus, it is also possible to specify two optional parameters in the user interface of SPMF:
- Max antecedent length: This parameter allows to set a maximum number of items to appear on the left side of a rule. By default, this parameter is equal to the infinity if it is not set.
- Max consequent length: This parameter allows to set a maximum number of items to appear on the right side of a rule. By default, this parameter is equal to the infinity if it is not set.
If you are using the command line interface of SPMF, it is also possible to use these optional parameters by adding them at the end of the command. For example:
java –jar spmf.jar run RPGrowth_association_rules contextRP.txt output.txt 60% 10% 60% 2 3
means to run the above example with a maximum antecedent length of 2 items and a maximum consequent length of 3 items.
Optional feature: giving names to items
Some users have requested the feature of given names to items instead of using numbers. This feature is offered in the user interface of SPMF and in the command line of SPMF. To use this feature, your file must include @CONVERTED_FROM_TEXT as first line and then several lines to define the names of items in your file. For example, consider the example database "contextRP.txt". Here we have modified the file to give names to the items:
@CONVERTED_FROM_TEXT
@ITEM=1=apple
@ITEM=2=orange
@ITEM=3=tomato
@ITEM=4=milk
@ITEM=5=bread
1 3 4
2 3 5
1 2 3 5
2 5
1 2 3 5
In this file, the first line indicates, that it is a file where names are given to items. Then, the second line indicates that the item 1 is called "apple". The third line indicates that the item 2 is called "orange". Then the following lines define four sequences in the SPMF format.
Then, if we apply the algorithm using this file using the user interface of SPMF or the command line, the output file contains several patterns:
milk ==> apple #SUP: 1 #CONF: 1.0
milk ==> 3 #SUP: 1 #CONF: 1.0
tomato milk ==> apple #SUP: 1 #CONF: 1.0
apple milk ==> tomato #SUP: 1 #CONF: 1.0
milk ==> apple tomato #SUP: 1 #CONF: 1.0
Performance
RPGrowth is the only algorithm for all rare itemsets that branch off initial singleton rare items offered in SPMF. Being an extension of FPGrowth; RPGrowth retains the speed, memory efficiency, and the usage of the FP-Tree.
Where can I get more information about the RPGrowth algorithm?
This is the journal article describing the original FPGrowth algorithm:
Jiawei Han, Jian Pei, Yiwen Yin, Runying Mao: Mining Frequent Patterns without Candidate Generation: A Frequent-Pattern Tree Approach. Data Min. Knowl. Discov. 8(1): 53-87 (2004)
This is the journal article describing the modification of the FPGrowth algorithm and FP-Tree to handle rare itemsets rather than frequent itemsets:
Sidney Tsang, Yun Sing Koh, Gillian Dobbie, RP-Tree: Rare Pattern Tree Mining, International Conference of Data Warehousing and Knowledge Discovery, 277-288 (2011)
https://link.springer.com/chapter/10.1007/978-3-642-23544-3_21