资源简介
少有的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
相关资源
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
评论
共有 条评论