# Data Mining Algorithms In R/Frequent Pattern Mining/The Eclat Algorithm

Introduction

## The Eclat Algorithm

The Eclat algorithm is used to perform itemset mining. Itemset mining let us find frequent patterns in data like if a consumer buys milk, he also buys bread. This type of pattern is called association rules and is used in many application domains.
The basic idea for the eclat algorithm is use tidset intersections to compute the support of a candidate itemset avoiding the generation of subsets that does not exist in the prefix tree. It was originally proposed by Zaki, Parthasarathy et al.

### Algorithm

The Eclat algorithm is defined recursively. The initial call uses all the single items with their tidsets. In each recursive call, the function IntersectTidsets verifies each itemset-tidset pair $\left\langle {X,t(X)}\right\rangle$ with all the others pairs $\left\langle {Y,t(Y)}\right\rangle$ to generate new candidates $N_{XY}$. If the new candidate is frequent, it is added to the set $P_{X}$. Then, recursively, it finds all the frequent itemsets in the $X$ branch. The algorithm searches in a DFS manner to find all the frequent sets.

### Implementation

The eclat algorithm can be found in the arule package of R system.
Usage
Arguments

#### data

    object of class transactions or any data structure which can be coerced into transactions (e.g., binary matrix, data.frame).

#### parameter

    object of class ECparameter or named list (default values are: support 0.1 and maxlen 5)

#### control

    object of class ECcontrol or named list for algorithmic controls.
Value
Returns an object of class itemsets
Example

### Visualization

The arules package implements some visualization methods for itemsets, which are the return type for the eclat algorithm. Here are some examples:
Example 1
Example 2
* Result of example 2
| # | items | support |
| 1 | {b, c, e} | 0.1 |
| 2 | {a, b, c} | 0.1 |
| 3 | {a, c} | 0.2 |
| 4 | {b, c} | 0.2 |
| 5 | {c, e} | 0.2 |
| 6 | {a, b,d, e} | 0.1 |
| 7 | {a, d, e} | 0.2 |
| 8 | {b, d, e} | 0.1 |
| 9 | {a, b, d} | 0.3 |
| 10 | {a, d} | 0.4 |
| 11 | {b, d} | 0.3 |
| 12 | {d, e} | 0.2 |
| 13 | {a, b, e} | 0.1 |
| 14 | {a, e} | 0.2 |
| 15 | {b, e} | 0.3 |
| 16 | {a, b} | 0.5 |
| 17 | {a} | 0.7 |
| 18 | {b} | 0.7 |
| 19 | {e} | 0.5 |
| 20 | {d} | 0.4 |
| 21 | {c} | 0.4 |

### Use Case

To see some real example of the use of the Eclat algorithm it will be used some data from the northwind database. The northwind database is freely available for download and represents data from an enterprise. In this example it will be used the table order details from the database. The order details table is used to relate the orders with products (in a n to n relationship). The Eclat algorithm will be used to find frequent patterns from this data to see if there are any products that are bought together.

#### Scenario

Given the data from the order details table from the northwind database, find all the frequent itemsets with support = 0.1 and length of at least 2.

#### Input Data

The order details table has the fields:

##### ID

    primary key

##### Order ID

    foreign key from table Orders

##### Product ID

    foreign key from table Products

##### Quantity

    the quantity bought

##### Discount

    the discount offered

##### Unit Price

    the unit price of the product
To use the data, some pre-processing is necessary. The table may have many rows that belongs to the same order, so the table was converted in a way that all the rows for one order became only one row in the new table containing the product id's of the products belonging to that order. The fields ID, order id, quantity, discount and unit price was discarded. The data was saved in a txt file called northwind-orders.txt. The file was scripted in a way ready to be loaded as a list object in R.

#### Implementation

To run the example the package arules need to be loaded in R.
First, the data is loaded in a list object in R
Second, the eclat algorithm is used.

#### Output Data

The itemsets object holds the output of the execution of the eclat algorithm. As can be seen above, 4 sets was generated. To see the results it can be used:

#### Analysis

As can be seen above, there are 4 frequent itemsets as result of the eclat algorithm. This output was induced by the replication of the transaction {11, 42, 72} many times in the data. This result shows that the tuples {11,42,72},{42,72} and {11,42} has a support of 19,40%; and the tuple {11,72} has a support of 19,60%.
The product id's 11, 42 and 72 represents the products Queso Cabrales, Singaporean Hokkien Fried Mee and Mozzarella di Giovanni, respectively. So, the output of the eclat algorithm suggests a strong frequent shop pattern of buying this items together.

### Variations
#### PPV, PrePost, and FIN Algorithm

These three algorithms were proposed by Deng et al, and are based on three novel data structures called Node-list, N-list, and Nodeset respectively for facilitating the mining process of frequent itemsets. They are sets of nodes in a FP-tree with each node encoding with pre-order traversal and post-order traversal. Compared with Node-lists, N-lists and Nodesets are more efficient. This causes the efficiency of PrePost and FIN is higher than that of PPV. See for more details.

## References

* Hahsler, M.; Buchta, C.; Gruen, B. & Hornik, K. arules: Mining Association Rules and Frequent Itemsets. 2009.
* Hahsler, M.; Gruen, B. & Hornik, K. arules -- A Computational Environment for Mining Association Rules and Frequent Item Sets. Journal of Statistical Software, 2005, 14, 1-25
* Mohammed Javeed Zaki, Srinivasan Parthasarathy, Wei Li. A Localized Algorithm for Parallel Association Mining. SPAA 1997: 321-330.
* Mohammed Javeed Zaki, Srinivasan Parthasarathy, Mitsunori Ogihara, Wei Li. New Algorithms for Fast Discovery of Association Rules. KDD 1997: 283-286.
* Mohammed Javeed Zaki, Srinivasan Parthasarathy, Mitsunori Ogihara, Wei Li. Parallel Algorithms for Discovery of Association Rules. Data Min. Knowl. Discov. 1(4): 343-373 (1997).
* Christian Borgelt (2003) Efficient Implementations of Apriori and Eclat. Workshop of Frequent Item Set Mining Implementations (FIMI 2003, Melbourne, FL, USA).
* 1 2 3 4 Deng, Z. & Wang, Z. A New Fast Vertical Method for Mining Frequent Patterns . International Journal of Computational Intelligence Systems, 3(6): 733 - 744, 2010.
* 1 2 3 4 Deng, Z.; Wang, Z. & Jiang, J. A New Algorithm for Fast Mining Frequent Itemsets Using N-Lists . SCIENCE CHINA Information Sciences, 55 (9): 2008 - 2030, 2012.
* 1 2 3 4 Deng, Z. & Lv, S. Fast mining frequent itemsets using Nodesets . Expert Systems with Applications, 41(10): 4505–4512, 2014.