FP-Growth算法python实现
2015-07-03 22:51
786 查看
前言:
关于关联分析和FP_Growth的介绍请见:什么是关联分析、FP-Growth算法的介绍。本文主要介绍用 python 语言实现 FP_Growth 算法的代码。
正文:
FP_Growth项目目录有四个文件:>FP_Growth
▪ __init__.py
▪ tree_builder.py
▪ tree_building.py
▪ tree_miner.py
其中,tree_builder.py 和 tree_building.py 文件主要负责FP-tree的构造,而 tree_miner.py 则是用来从构造好的FP-tree上提取频繁项集。
主程序所在的文件“__init__.py”代码如下:
#coding=utf-8 import tree_builder import tree_miner routines = [ ['Cola','Egg','Ham'], ['Cola','Diaper','Beer'], ['Cola','Beer','Diaper','Ham'], ['Diaper','Beer'] ] #事务数据集 min_sup = 2 #最小支持度计数 headerTable = {} #头结点表,用来存放各个项的索引 treeBuilder = tree_builder.Tree_builder(routines=routines, min_sup=min_sup, headerTable=headerTable) #建造FP_Tree tree_miner.Tree_miner(Tree=treeBuilder.tree, min_sup=min_sup, headerTable=headerTable) #对FP_Tree进行频繁项集的挖掘
__init__.py 主要实现下面三个动作:
输入事务数据集 routines 和最小支持度计数 min_sup ;
调用 Tree_builder 构造 FP-tree,见 FP-Growth算法之 FP-tree 的构造(python);
调用 Tree_miner 从FP-tree提取频繁项集,见 FP-Growth算法之频繁项集的挖掘(python);
代码地址:\color{red}{代码地址:}FP-Growth算法python实现(完整代码)。
备注:该代码是在 Python2.7+eclipse 环境下编写的。可在eclipse中导入项目,也可在命令行窗口用python命令执行“__init__.py”文件。
转载请注明出处,谢谢!(原文链接:/article/1365150.html)
相关文章推荐
- 用Python完成猜随机数的游戏
- MAC OS上切换python2与python3环境
- python实践编程
- Python的os.walk()方法详细讲解
- Python笔记:_mysql常用操作
- python install pycurl
- Python笔记:MySQLdb模块常用操作
- Python - 函数/方法装饰器
- Python 自动化测试报告HTMLTestRunner
- Python 自动化测试报告HTMLTestRunner
- Python中logging.config配置文件解读
- Ubuntu下安装Python3.4
- python3.x __name__ == '__main__'
- python使用post方式发送json参数
- Python3.4字符串包含 & 集合
- Python正则表达式
- Python3.4-文本-替换字符串中的子串
- Python3.4字符串对齐/删除空格/合并/反转
- Python3.4字符串基础及每次处理一个字符
- Windows下Python添加库(模块)路径