FPGROWTH Algorithm for Association rules

Source: Internet
Author: User

Aprori algorithm uses two characteristics of frequent sets, filtering a lot of unrelated sets, the efficiency is improved a lot, but we found that the Apriori algorithm is a candidate elimination algorithm, each elimination needs to scan all data records, resulting in the entire algorithm in the face of large data set is Powerless. Today we introduce a new algorithm mining frequent itemsets, the efficiency is much higher than the Aprori algorithm.

The fpgrowth algorithm compresses data records by constructing a tree structure, making mining frequent itemsets only need to scan two data records, and the algorithm does not need to generate candidate sets, so the efficiency is Higher. Let's also be an example of the data set used in the previous article:

TID Items
T1 {milk, bread}
T2 {bread, diapers, beer, eggs}
T3 {milk, diapers, beer, coke}
T4 {bread, milk, diapers, beer}
T5 {bread, milk, diapers, coke}

first, the construction Fptree

Fptree is a tree structure, and the tree structure is defined as Follows:

 public class fpnode {    String idname; // ID number    List<fpnode> children; // Children's Knot.    Fpnode parent; // parent Node    Fpnode next; // next node    with the same ID number Long count; // number of occurrences }  

Each node of the tree represents an item, here we are not anxious to see the structure of the tree, we demonstrate the construction process of the fptree, fptree the structure of the natural understanding of the Tree. Let's say we have a minimum absolute support of 3.

  Step 1: Scan the data records, generate a frequent itemsets, and sort by the number of occurrences, as Follows:

Item Count
Milk 4
Bread 4
Diapers 4
Beer 3

can see, eggs and Coke did not appear in the table, because Coke only appeared 2 times, eggs only appear 1 times, less than the minimum support, so not frequent itemsets, according to Apriori theorem, Non-frequent itemsets is not a frequent item set, so coke and eggs do not need to be considered.

 Step 2: scan the data record again for the items in each record that appear in the table that is generated in Step 1, sorted by the order in the Table. initially, a new root node is created, marked as null;

  1) First record:{milk, bread}, sorted by step 1 table filtered to get still {milk, bread}, create a new node, idname {milk}, Insert it under the root node, set count to 1, and create a new {bread} Node. Insert below the {milk} node and insert the following as Follows:

  2) The second record:{bread, diapers, beer, eggs}, filtered and sorted after:{bread, diapers, beer}, found that the root node does not contain {bread} son (have a {bread} grandson but not son), so create a {bread} node, Inserted under the root node, so that the root node has two children, and then the new {diaper} node inserted under the {bread} node, the new {beer} node inserted under {diaper}, after inserting as Follows:

  3) Third record:{milk, diapers, beer, cola}, filtered and sorted after: {milk, diapers, beer}, This time found that the root node has a son {milk}, so do not need to create a new node, just the original {milk} The count of the nodes plus 1, then found {milk} node has a son {diaper}, so create a new {diaper} node, and insert into the {milk} node below, and then the new {beer} node inserted behind the {diaper} Node. Insert the following as Shown:

  4) Fourth record:{bread, milk, diapers, beer}, filtered and sorted after:{milk, bread, diapers, beer}, This time found that the root node has a son {milk}, so do not need to create a new node, just the original {milk} node count plus 1, Find a son {bread} at the end of the {milk} Node. so do not need to create a new {bread} node, just the original {bread} node count plus 1, because this {bread} node has no son, at this time need to create a new {diaper} node, inserted under the {bread} node, and then create a new {beer} node, inserted in {diaper} Below the node, insert the following as Shown:

  

  5) Fifth record:{bread, milk, diapers, cola}, filtered and sorted after: {milk, bread, diapers}, Check found root node has {milk} son, {milk} node has {bread} son, {bread} node has {diaper} son, This insertion does not require a new node to update count, as Follows:

  

Following the above steps, we have basically constructed a fptree (frequent Pattern tree), The daily Path in the tree represents an item set, because many itemsets have public items, and the more occurrences of the items are more likely to be father-in-law, so that the number of occurrences from the order of many to less can save space, The implementation of compressed storage, In addition we need a table header and each idname the same node to do a clue, convenient for later use, the structure of clues is also formed in the building process, but in order to simplify the Fptree generation process, I did not mention in the above, this in the code is reflected, The fptree for adding clues and headers are as Follows:

  At this point, the entire fptree is constructed, and in the following excavation we will see the function of the table header and Clues.

second, mining frequent itemsets with Fptree

After the Fptree is built, it is possible to dig the frequent itemsets, the mining algorithm is called the fpgrowth (frequent Pattern Growth) algorithm, and the mining starts from the last item in the header header of the Table.

  1) here, starting with {beer}, find all {beer} nodes based on the lead chain of {beer}, and then find the branch of each {beer} node: {milk, bread, diapers, beer: 1},{milk, diaper, beer: 1},{bread, diaper, beer: 1}, of which "1" The expression appears 1 times, note that although {milk} appears 4 times, but {milk, bread, diapers, beer} appears only 1 times, so the count of the branch is determined by the suffix node {beer}, minus {beer}, we get the corresponding prefix path {milk, bread, diaper: 1},{milk, Diaper : 1},{bread, diaper: 1}, According to the prefix path we can generate a conditional fptree, constructed as before, where the data record becomes:

TID Items
T1 {milk, bread, diapers}
T2 {milk, diapers}
T3 {bread, diapers}

The absolute support level is still 3, and the resulting fptree are:

After the condition tree is constructed, the conditional tree is recursively mined, and when the condition tree has only one path, all the combinations of the paths are conditional frequent sets, assuming that {beer} is frequently set to {s1,s2,s3}, the frequent set of {beer} is {s1+{beer},s2+{beer},s3+{beer}}, i.e. {beer The frequent set of} must have the same suffix {beer}, where the condition is frequently set to: {{},{diaper}}, so {beer} 's frequent set is {{beer} {diaper, beer}}.

  2) Then find the last number of the second item {diaper} of the header table, and the prefix path of {diaper} can be obtained as follows: {bread: 1},{milk: 1},{milk, bread: 2}, the dataset for conditional Fptree Is:

TD style= "text-align:center" align= "center" valign= "middle" >t2 /tbody>
tid items
t1 {bread}
{milk}
t3 {milk, bread}
t4 {milk, bread}

Note {milk, bread: 2}, which is {milk, bread} count is 2, so in {milk, bread} repeated two times, so that the purpose is to use the previously constructed Fptree algorithm to construct the condition fptree, but this efficiency will be reduced, imagine if {milk, bread} Count is 20000, then you need to expand into 20,000 records and then make 20,000 count updates, and in fact only need to update count once to 20000. This is achieved on the optimization details, in practice when Attention. The conditions for construction are fptree:


This condition tree is already a single path, and all combinations on the path are conditional frequent sets: {{},{milk},{bread},{milk, bread}}, plus {diaper}, get a set of frequent itemsets {{diaper},{milk, diaper},{bread, diaper},{milk, bread, diaper}}, This set of frequent itemsets must contain an identical suffix: {diaper}, and does not contain {beer}, so this set of frequent itemsets is not duplicated with the previous Group.

Repeat the above steps, the header header of each item mining, you can get the entire frequent itemsets, it is possible to prove (rigorous algorithm and proof of the visible reference [1]), frequent itemsets are not duplicated or omitted.

The implementation code for the program is still on my github, and Here's a look at the results of the operation:

Absolute Support Degree: 3 frequent itemsets     : bread diaper 3 diaper milk      3 milk      4 bread milk      3 Diaper beer      3 Bread      4

In addition I downloaded a shopping basket data set, The volume of data is large, testing the efficiency of the fpgrowth is Good. The average efficiency of the fpgrowth algorithm is much higher than the Apriori algorithm, but it does not guarantee high efficiency, its efficiency depends on the data set, when there are no common items in the frequent itemsets in the dataset, all itemsets are hung on the root node, the compressed storage is not implemented, and the Fptree requires additional Overhead. Need more storage space, before using the Fpgrowth algorithm, analyze the data to see if it is appropriate to use the Fpgrowth algorithm.

The next article will introduce the evaluation criteria of association rules, and welcome the continuous Attention.

Reference Documents :

[1]. Han Jia wei, Pei Jan et Mining frequent Patterns without candidate generation:a Frequent-pattern Tree approach.2004

Thank you for your attention, welcome reply exchange!

Reprint Please specify source: http://www.cnblogs.com/fengfenggirl

FPGROWTH Algorithm for Association rules

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.