Fp_growth algorithm Python implementation

Source: Internet
Author: User

The fp_growth algorithm is an excellent method in association analysis, which maps the whole transaction database to the tree structure by constructing fp_tree, which greatly reduces the time to scan the database frequently.
The fp_growth algorithm is divided into two steps, the first step is to construct the Fp-tree, and the second step is to extract the frequent itemsets from the Fp-tree.
For more information on correlation analysis and fp_growth and pseudo-code see: What is correlation analysis, fp-growth algorithm introduction.

The main purpose of this paper is to introduce the code of Python implementation fp_growth algorithm.

The Fp_growth project directory has four files:

>fp_growth
? __init__.py
? tree_builder.py
? tree_building.py
? tree_miner.py

Among them, tree_builder.py and tree_building.py files are mainly responsible for the fp-tree structure, while tree_miner.py is used to extract frequent itemsets from the constructed fp-tree.

The file "\__init__.py" where the main program resides is as follows:

#coding =utf-8ImportTree_builderImportTree_minerroutines = [[' Cola ',' Egg ',' Ham '],           [' Cola ',' Diaper ',' Beer '],           [' Cola ',' Beer ',' Diaper ',' Ham '],           [' Diaper ',' Beer ']        ]#事务数据集Min_sup =2                             #最小支持度计数headertable = {}#头结点表, the index used to store individual itemsTreebuilder = Tree_builder. Tree_builder (Routines=routines, Min_sup=min_sup, headertable=headertable)#建造FP_TreeTree_miner. Tree_miner (Tree=treebuilder.tree, Min_sup=min_sup, headertable=headertable)#对FP_Tree进行频繁项集的挖掘

It mainly achieves three actions:

    1. Input transaction data set routines;
    2. Call Tree_builder, construct fp-tree;
    3. Call Tree_miner, extract frequent itemsets from Fp-tree;


Fp-tree structure See: Fp-growth algorithm Python implementation of the FP-TREE structure
Mining frequent itemsets see: Mining of frequent itemsets implemented by fp-growth algorithm Python



GenerationCodetoAddress: Fp-growth algorithm python implementation (full code).
Note: This code is written in a python2.7+eclipse environment. You can import the project in Eclipse, or you can execute the "__init__.py" file with the python command in the command-line window.

Copyright NOTICE: Reprint Please indicate the source, thank you!

Fp_growth algorithm Python implementation

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.