Association Analysis: FP-growth algorithm

Source: Internet
Author: User

Association Analysis, also known as association mining, is to search for frequent patterns, associations, correlations, or causal structures between project sets or object sets in transaction data, relational data, or other information carriers. A typical example of association analysis is basket analysis. Analyzes customers' purchasing habits by finding the relationship between different products in the shopping basket. For example, 67% of customers buy beer while buying diapers. By understanding which products are frequently purchased by customers at the same time, you can help retailers develop marketing strategies. Association analysis can also be applied to other fields, such as bioinformatics, medical diagnostics, Web Mining, and scientific data analysis.

 

1. Problem definition

Figure 1 dual representation of shopping basket data

Figure 1 shows the shopping basket data of a customer. Each row is the shopping record of each customer, corresponding to a transaction, and each column corresponds to one item. Make I = {I _1, I _2 ,..., I _d} is a set of all items in the shopping basket data, and t = {T_1, T_2 ,..., t_n} is a collection of all transactions. Each t_ I contains a subset of I. In Association Analysis, a set of 0 or more items is called an itemset ). The so-called Association Rules refer to expressions like X → y, where X and Y are non-Intersecting items. There are two important concepts in association analysis --Support(Support) andConfidence Level(Confidence ). The support determination rule can be used to specify the frequency of a dataset, while the confidence level determines the frequency of transactions in which y appears. The supported (s) and confidence (c) measurements are defined as follows:

Formula 1

N indicates the total number of transactions. The association rule has a low level of support, indicating that it is only accidental and does not make much sense. On the other hand, the confidence level can measure the reliability of reasoning through association rules. Therefore, most associated analysis algorithms adopt the following policies:

(1) frequent item set generation: the goal is to find all item sets that meet the minimum support threshold. These item sets are called frequent item sets.

(2) Rule Generation: the goal is to extract all high-confidence rules from the frequent items found in the previous step. These rules are called strong rules.

 

2. Build a FP-tree

The FP-growth algorithm compresses the information in the transaction database by constructing a FP-tree to generate frequent item sets more effectively. FP-tree is actually a prefix tree, which is arranged in descending order of support. The more frequent items with higher support, the closer they are to the root node, so that more frequent items can share the prefix.

Figure 2 transaction database

Figure 2 shows the transaction database used for basket analysis. Among them, a, B,... and P indicate the items purchased by the customer respectively. First, the transaction database is scanned once to calculate the support of various items in each row of records, and then sorted in descending order according to the support level. Only frequent item sets are retained, remove the items that are lower than the support threshold. Here, set the support threshold to 3 to get <(F: 4), (C: 4), (A: 3), (B: 3), (M: 3, (P: 3)> (since N in the formula for calculating the degree of support remains unchanged, only the numerator in the formula needs to be compared ). The 3rd column in Figure 2 shows the sorting result.

The root node of the FP-tree is null and does not represent any items. Next, perform the second scan on the transaction database to start building the FP-tree:

The first record <F, C, A, M, P> corresponds to the first branch in the FP-tree <(F: 1), (C: 1), (A: 1 ), (M: 1), (P: 1)>:

Figure 3 first record

Because the second record <F, C, A, B, m> has the same prefix as the first record <F, C, A>, <F, C, a> Add one of the supported values, and add the nodes (B: 1) and (M: 1) Under (A: 2) respectively ). Therefore, the second branch in the FP-tree is <(F: 2), (C: 2), (A: 2), (H: 1), (M: 1)>:

Figure 4 second record

The third record <F, B> has only one prefix <F> compared with the first two records. Therefore, you only need to add a node under (F: 3) <B: 1>:

Figure 5 third record

The Fourth Record <C, B, P> does not have a common prefix with all previous records. Therefore, add nodes (C: 1), (B: 1), (P: 1 ):

Figure 6 record 4

Similarly, the fifth record <F, C, A, M, P> is used as a branch of the FP-tree to update the support of related nodes:

Figure 7 Fifth record

To facilitate the whole tree traversal, an item header table is created ). The first column of this table lists the frequent items in descending order. The second column is a pointer to the position of the frequent item in the FP-Tree node. Each node in the FP-tree also has a pointer to a node with the same name:

Figure 8 FP-tree

In summary, the FP-Tree node can be defined:

Class treenode {PRIVATE: string name; // node name int count; // support count treenode * parent; // parent node vector <treenode *> children; // subnode treenode * nexthomonym; // point to the Same Name node ...}

 

3. Frequent Patterns)

We start from the bottom of the table to mine frequent patterns in the FP-tree. There are two node chains ending with P in the FP-tree: <(F: 4), (C: 3), (A: 3), (M: 2 ), (P: 2)> and <(C: 1), (B: 1), (P: 1)>. The first node linked list shows the list of items purchased by the customer <F, C, A, M, P> twice in the database. Note that, although <F, C, A> appears three times in the first node chain, <F> appears four times in a single item, however, they appear only twice with P, so in the condition FP-tree, <(F: 4), (C: 3), (A: 3), (M: 2), (P: 2)> as <(F: 2), (C: 2), (A: 2), (M: 2), (P: 2)>. Similarly, the second node chain indicates that the list of items purchased by the customer <C, B, P> only appears once in the database. We set the prefix node chains of P <(F: 2), (C: 2), (A: 2), (M: 2)> and <(C: 1 ), (B: 1)> A condition pattern base called P ). The condition FP-tree for P is:

Figure 9 condition FP-tree of P

Conditional FP-tree mining is divided into two steps. First, determine whether the current node meets the threshold. Here (P: 3) satisfies the requirements of the support threshold, so the Frequent Items (P: 3 ). Then, check whether there are any nodes that meet the threshold value in the condition FP-tree of the current node. If not, output the current frequent item set and exit recursion. If yes, select a node from the condition FP-tree and recursively mine the condition FP-tree. This process will be discussed in detail below. As shown in Figure 9, only (C: 3) in the condition fp-tree of P meets the requirements of the support threshold. Therefore, the frequent item set ending with P is only (P: 3 ), (CP: 3 ).

There are two node chains ending with m in the FP-tree: <(F: 4), (C: 3), (A: 3), (M: 2)> and <(F: 4), (C: 3), (A: 3), (B: 1), (M: 1)>. Therefore, the condition mode base of M is <(F: 2), (C: 2), (A: 2)> and <(F: 1), (C: 1 ), (A: 1), (B: 1)>. Because (B: 1) does not meet the support threshold, you only need to consider <(F: 2), (C: 2), (A: 2)> and <(F: 1), (C: 1), (A: 1)> merged frequent item set <(F: 3), (C: 3), (A: 3)>:

Figure 10 condition FP-tree of m

Different from P, M's condition FP-tree has three nodes, so it is necessary to recursively mine frequent item sets (<(F: 3), (C: 3 ), (A: 3) | (M: 3)> ). Recursively call mine (<(F: 3), (C: 3), (F: 3), (C: 3) | a, m>), Mine (<(F: 3) | C, M>), Mine (null | f, m ). Because (M: 3) satisfies the support threshold, the frequent itemset ending with M has {(M: 3 )}.

Figure 11 condition FP-tree for node (a, m)

As shown in figure 11, the condition FP-tree of a node (a, m) has two nodes and needs to call mine (<(F: 3) | C,, m>) and mine (<null | f, a, m> ). Recursive mine (<(F: 3) | C, A, M>) to generate mine (<null | f, C, A, M> ). Therefore, frequent item sets ending with (a, m) include {(AM: 3), (FAM: 3), (CAM: 3), (FCAM: 3 )}.

  

Figure 12 condition FP-tree for node (C, M)

As shown in figure 12, the condition FP-tree of a node (C, M) has only one node, so you only need to recursively call mine (<null | f, C, M> ). Therefore, frequent item sets ending with (C, M) include {(CM: 3), (FCM: 3 )}. Similarly, frequent item sets ending with (F, m) include {(FM: 3 )}.

There are three node chains ending with B in the FP-tree: <(F: 4), (C: 3), (A: 3), (B: 1) >,< (F: 4), (B: 1)> and <(C: 1), (B: 1)>. Because of Node B's condition mode base <(F: 1), (C: 1), (A: 1) >,< (F: 1)> and <(C: 1)> The support threshold is not met, so recursion is not required. Therefore, the frequent item set ending with B is only (B: 3 ).

Likewise, we can obtain the frequent item sets ending with a {(FA: 3), (CA: 3), (FCA: 3), (A: 3 )}, frequent Item set ending with c {(FC: 3), (C: 4)}, and frequent item set ending with f {(F: 4 )}.

 

4. Discussion

Prior to Professor Han's proposal of the FP-growth algorithm, the association analysis generally adopted the Apriori and its deformation algorithms. However, the Apriori and its deformation algorithms need to scan the database multiple times and generate an exponential candidate item set, with unsatisfactory performance. The FP-growth algorithm uses an efficient data structure FP-tree, which eliminates the need to scan databases multiple times and generate a large number of candidate items.

The FP-tree in a single path does not require recursion. It can be directly generated by means of permutation and combination. Professor Han Jiawei mentioned in his thesis the single path optimization algorithm. The paper also mentions how to adjust the FP-growth algorithm to adapt to the data volume in the face of big data.

 

5. References

[1] Mining Frequent Patterns without candidate generation. Jiawei Han, Jian Pei, and Yiwen Yin. Data Mining and knowledge discovery. Volume 8 Issue 1. January 2004. [PDF]

[2] Frequent Pattern Mining II (FP growth algorithm). yfx416. software engineer in NRC. 2011. [LINK]

[3] implementation of the FP-tree algorithm. orisun. China 35 degrees. 2011. [LINK]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.