资源简介
基于《机器学习实战》中FP-Growth的代码修改形成的频繁项集挖掘函数FP_Growth(),可显示各频繁项集的支持度;同时,还包括关联规则发现函数findRules()。
代码片段和文件信息
class treeNode:
def __init__(self nameValue numOccur parentNode):
self.name = nameValue
self.count = numOccur
self.nodelink = None
self.parent = parentNode #needs to be updated
self.children = {}
def inc(self numOccur):
self.count += numOccur
def disp(self ind=1):
print(‘ ‘*ind self.name ‘ ‘ self.count)
for child in self.children.values():
child.disp(ind+1)
def createTree(dataSet minSup=1): #create FP-tree from dataset but don‘t mine
headerTable = {}
#go over dataSet twice
for trans in dataSet:#first pass counts frequency of occurance
for item in trans:
headerTable[item] = headerTable.get(item 0) + dataSet[trans]
f
评论
共有 条评论