资源简介
少有的fpgrowth算法的python实现。只要传入数据集,就可计算出频繁模式集。
代码片段和文件信息
#!/usr/local/bin/python3
# Desc: FP-growth algorithm for extracting the association rules
# Auther: Gunther
# Date: 2012/07/18
# Log:
# created by wjg 2012/07/18
import os
import sys
import FPTree
class FPGrowth:
def __init__(self minsup=2):
self.fp = []
self.minsup = minsup
def growth(self tree postNodes):
if tree.isUniquePath():
nodeCombinations = []
tree.getCombinationFromPath(nodeCombinations)
for combination in nodeCombinations:
support = self._getMinSupport(combination)
if support is None or support < self.minsup:
continue
#gen pattern
pattern = ([]support)
for node in combination:
pattern[0].append(node[“name“])
for node in postNodes:
pattern[0].append(node)
if len(pattern[0]) > 1:
self.fp.append(pattern)
#self._printPattern(pattern)
else:
for item in tree.itemTable:
#gen pattern
pattern = ([]tree.itemTable[item][0])
pattern[0].append(item)
for node in postNodes:
pattern[0].append(node)
if len(pattern[0]) > 1 and pattern[1] > self.minsup:
self.fp.append(pattern)
#self._printPattern(pattern)
#construct conditional pattern base
baseSet = []
tree.getConditionalPatternbase(itembaseSet)
tmpTree = FPTree.FPTree(baseSet minsup=self.minsup)
tmpTree.build()
if not tmpTree.isEmpty():
self.growth(tmpTree pattern[0])
def _getMinSupport(self nodes):
if len(nodes) == 0:
return None
support = nodes[0][“support“]
for node in nodes:
if node[“support“] < support:
support = node[“support“]
return support
def _printPattern(self pattern):
if len(pattern[0]) < 2:
return
print(“*******************“)
print(pattern[0])
print(pattern[1])
print(“*******************“)
def test():
#testcase = [[[“i2““i1““i5“]1][[“i2““i4“]1][[“i2““i3“]1][[“i2““i1““i4“]1][[“i1““i3“]1][[“i2““i3“]1][[“i1““i3“]1][[“i2““i1““i3““i5“]1][[“i2““i1““i3“]1]]
testcase = [[[“a““b“]1][[“b““c““d“]1][[“a““c““d““e“]1][[“a““d““e“]1][[“a““b““c“]1][[“a““b““c““d“]1][[“a“]1][[“a““b““c“]1][[“a““b““d“]1][[“b““c““e“]1]]
#testcase = [([“i1““i2“]1)([“i3“]1)]
tree = FPTree.FPTree(testcaseminsup=2)
tree.build()
algorithm = FPGrowth(minsup=2)
algorithm.growth(tree[])
res = sorted(algorithm.fp key=lambda d:d[1] reverse = True )
for rule in res:
pri
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3077 2012-07-25 15:56 FPGrowth.py
文件 8058 2012-07-25 14:43 FPTree.py
相关资源
- win32 API 中文版,适用于所有的python版
- 图像识别/自动完成拼图验证码的dem
- 自己用python写的后门
- 度分秒与十进制批量转换
- Learn Python the Hard Way 中文版第三版
- HTMLTestRunnerCN.py
- HAP-NodeJS虚拟设备配置及python脚本
- python3下的PBC库
- Python成绩管理系统精简版
- 最全Python编程基础+简单爬虫+进阶项目
- python端口扫描代码源码
- python wxpy实现微信群消息转发
- Python_验证采样定理.py
- python爬虫爬微信公众号文章
- Python网络爬虫实战Scrapy.txt
- micropython下的ds18b20代码
- knn 字符识别 python
- EM算法Python实现
- 简单的python购物车程序
- 是AI就躲个飞机-纯Python实现人工智能
- Python接口测试框架实战与自动化进阶
- 基本蚁群算法python实现
- python核心编程第二版习题答案
- 基于二维伽马函数的光照不均匀的图
- python主题爬取百度新闻
- MySQL-python-1.2.5.win-amd64-py2.7
- nao机器人单个关节运动程序
- Python - Flask 使用Ajax 实现多文件上传
- Python魔鬼训练营系列教程
- 多线程爬虫
评论
共有 条评论