Association rules: Operation of the apriori algorithm
By: Martin Bernaola
Tags: Data Mining, Artificial Intelligence, Programming, Apriori Algorithm, Rules

Both algorithms can be downloaded from GitHub, in the Datasets folder, there are files to test. At the end of the post is the Complete Paper (In Spanish).

Data mining consists of analyzing volumes of data from different tools or techniques that facilitate this process, such as, for example, the a priori algorithm, FP-Growth, aprioriTID, aprioriHybrid, Eclat, Top-k rules, etc. Today the applicability of data mining can be seen in many areas such as medicine, biology, or business enterprises.

Association Rules

The association rules show correlations found from the analysis of a large set of transactions. These rules are represented with an antecedent X and a consequent Y.

The most common techniques for obtaining these rules use two parameters, support, and trust. The first is calculated with respect to the set of transactions T and indicates what percentage of transactions contain X.

Support = (Number of Transactions Containing X) / (Total Number of Transactions)

The second indicates what percentage of the transactions that contain X also contain Y, and is given by:

Trust= Support (X U Y) / Support (X)

Each rule indicates that if X is satisfied, there is a certain probability given by its confidence that Y is also satisfied.

Apriori algorithm

Github Code:

The algorithm discovers all the possible rules from support and minimal trust. It is divided into two main parts. The first consists of obtaining the sets of frequent items (itemsets) and the second the rule generation.

Example

FP-Growth algorithm (Alternative)

Github Code

Like the a priori algorithm, it generates all possible rules and consists of two parts which are the identification of frequent items and another characteristic of the generation of rules using trust and support as threshold values. The difference of FPGrowth in the generation of sets of frequent elements is based on building a tree.

This tree is built with the frequent items (that is, those that exceed the minimum established support) so that those with the highest frequency will be located at the top of the tree, while each branch is created by going through the set of transactions with the frequent items already ordered descending.

Full paper in Spanish

The DataSets are assembled as follows:

Orange Line -> Trust / Blue Line -> Support

It can be seen in Next Picture, how by changing both parameters (Trust and Support) the number of generated rules will decrease in both cases. Whenever one of the parameters increases, the number of rules will be less, due to the characteristics of the a priori algorithm. The variation of the support impacts more, generating a much smaller number of rules than if the confidence were varied.

Performance

The performance of the algorithms according to the number of rules generated varying the support.

Conclusions

The a priori algorithm for the generation of association rules does not have the ability to make decisions regarding the outputs generated based on the domain in which they are found, that is, they return as much as possible and this is observed in the enormous number of rules that is generated in this post. That is why it would be a good alternative to adapt the solution to the specific needs of the business.