"Machine Learning" Association rules and Fp-tree

Source: Internet
Author: User
Fp-tree Algorithm

The fp-tree algorithm only needs to traverse a single transaction, and then it can establish a fp-tree tree data structure to characterize the relationship between transactional items. Fp-tree compresses each transaction to a tree compared to the original transaction, saving the relationship between the items and the frequency, but the scale is much smaller. I can get the number of occurrences of all transactional item collections directly based on Fp-tree.
Here is the initialization step:
1, the transaction item sort. Suppose I get the transaction T, first calculate the number of occurrences of each transaction item, and remove the transaction item with a single transaction item less than the threshold because the parent collection of these transactional items must not be a frequent set. The remaining transaction items are 1-yuan frequent sets, which are called F1 by the number of occurrences of the descending sequence list. Set F1 table as: a,b,c,d
2. Re-sort each transaction according to the order of the F1. Set a transaction as: C,d,a, then reorder to a,c,d.
3, each orderly transaction is a path, I can build a tree according to the path, the root node of the book is set to null. If the project transaction is ACD,ABC,BC, then you can build the tree, and the tree node colon follows the number of occurrences:
  
The Fp-tree algorithm starts here to enter the recursive step, the algorithm is (http://www.cnblogs.com/zhangchaoyang/articles/2198946.html):
  

 input: Transaction set list<list<string>> transactions output: Frequent pattern set and corresponding frequency map<list<string >,Integer> Frequentpattens Initialize postmodel=[],cpb=transactions void Fpgrowth (list<list<string>> CPB, List<string> Postmodel) {if CPB is empty: return counts the count of each item in the CPB, drops the count by less than the minimum support number minsuport, and drops by item count for each transaction in the CPB
    Sequential arrangement. Built by CPB Fp-tree,fp-tree contains the header entry headers, each header points to a list headerlinklist, each element in the list is a node on the Fp-tree,
    and the node name is the same as header.name. For the header in Headers:newpostmodel=header.name+postmodel, add <newpostmodel, header.count> to Frequentpat
        The Tens. Newcpb=[] for TreeNode in headerlinklist: Get the full path from the root node of the fp-tree to the TreeNode, add path as a transaction to the NEWCPB, and add t repeatedly
        Reenode.count times. Fpgrowth (Newcpb,newpostmodel) 

Assuming that currently known frequent set B, I'm looking for a parent frequent set that contains B and is a frequent set, you need to find all the paths from the root node to B to build a new fp-tree. b is the Postmodel suffix mode, abbreviated to PM; the set of all paths of the root node to B is the CPB conditional pattern base. There may be duplicate paths in the CPB, or there is a repetition of the different paths, and in the iterative process, the CPB is used to build the fp-tree with the support information. The support degree of a sub-node of a single fork in the Fp-tree must be less than or equal to the support of the parent node, but the total support of the child node may be more than one parent node of that child node (case two). This is the ordered result obtained after sorting the transaction. Assume that the support threshold is at least 3 times.
The above iteration function fpgrowth, the first step of the input, CPB is the original, excluding the 1-yuan non-frequent set of transaction paths, PM is empty, writing null, you can think of the root node to null path is all the initialization transaction path; Header headers are, of course, F1 tables. The first step I traverse the F1 table, the items on the table already meet the support criteria, so I will null and combine these items so that all the 1-dollar frequent sets are found. Then traverse these 1-yuan frequent sets, reverse-order the headers element x as the NEWPM, findCurrent Fp-treeAll paths in the root node to X are used as NEWCPB, and the next iteration of X is fpgrowth; After the search for X is complete, return to the search for the last element w of X. The whole process is similar to deep search.
Assuming that D frequent sets (containing N elements, n>0) are PM, known as CPB, then I rebuilt Fp-tree, and a new header entry Headers,headers Save the total occurrences of elements present in the current fp-tree. Nodes that are less than the support threshold can be pre-ruled out. I draw the situation (1):
  
Since my CPB is the root node to all paths to D, if there is only one path in the Fp-tree, then the nodes on this path can go to D three times, can coexist with each other 3 times, the ABC any combination satisfies the support threshold value. So ABC can be any combination, and then end with a D suffix pattern composed of frequent sets, the number of occurrences is 3, added confidence in the calculation queue, the search for D end. Note that the path of the real transaction, such as A->b, may be greater than 3, the extra path is not to D, when I build the CPB of D, the excess path is excluded; In this round of analysis, only the frequent sets and frequencies containing d can be obtained, for example, the actual path frequency of a->b may be greater than 3. Although I can assume that AB is a frequent set, it is not possible to obtain the true frequency of the frequent set, which must be calculated in subsequent iterations.
If there are multiple paths for the new fp-tree, then I must use the headers header to analyze it uniformly, not along the fork of the tree. I draw the situation two:
  
As you can see, the items in the first and second paths have a support level of 2, but the CD is a frequent set. If you simply analyze each fork, you will get the wrong conclusion that there is no frequent set. At this point I need to use the new header item that I just created headers:
A:2 b:2 C:4 (d:4)
Depending on the header entry, C has a support level of 4, which means that suffix mode D can be synthesized with the C group as a frequent set with a support degree of 4 and then as a new suffix mode CD. In the next iteration, the support level for the first path of the new CPB (A:2-&GT;B:2) does not meet the criteria, the second path is empty, and the frequent set search with D is complete.
  Now let me see if this iterative process can fully search all the frequent sets. In one fp-tree iteration, our search starts with a low-level transactional project in the Header table, which guarantees a search order. The construction of the new Fp-tree strictly follows the order of the individual transactional items of the header header at the first build of the Fp-tree, and the sorted transaction items in the table header are never in front of the pre-sorted transactional items in the tree's single fork. Thus, assuming that the transaction item has ABCD, starting with the D iterative search, you can scan all candidate frequent sets that contain D; Starting with C, the candidate frequent sets that contain C and do not contain d are scanned so that they do not repeat. After an iterative search, all possible candidate frequent sets are scanned.

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.