From 19b8689d2e3621e9f3b638d755edbf0aedf2469e Mon Sep 17 00:00:00 2001 From: jiangzhonglian Date: Sun, 2 Apr 2017 23:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=2012.fpGrowth=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/python/12.FrequentPattemTree/fpGrowth.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/python/12.FrequentPattemTree/fpGrowth.py b/src/python/12.FrequentPattemTree/fpGrowth.py index 46639ca0..42a9f3f7 100644 --- a/src/python/12.FrequentPattemTree/fpGrowth.py +++ b/src/python/12.FrequentPattemTree/fpGrowth.py @@ -41,6 +41,7 @@ def loadSimpDat(): ['z', 'y', 'x', 'w', 'v', 'u', 't', 's'], ['z'], ['r', 'x', 'n', 'o', 's'], + # ['r', 'x', 'n', 'o', 's'], ['y', 'r', 'x', 'z', 'q', 't', 'p'], ['y', 'z', 'x', 'e', 'q', 's', 't', 'm']] return simpDat @@ -49,7 +50,10 @@ def loadSimpDat(): def createInitSet(dataSet): retDict = {} for trans in dataSet: - retDict[frozenset(trans)] = 1 + if not retDict.has_key(frozenset(trans)): + retDict[frozenset(trans)] = 1 + else: + retDict[frozenset(trans)] += 1 return retDict @@ -193,7 +197,7 @@ def findPrefixPath(basePat, treeNode): # prefixPath[1:] 变frozenset后,字母就变无序了 # condPats[frozenset(prefixPath)] = treeNode.count condPats[frozenset(prefixPath[1:])] = treeNode.count - # 递归,寻找改节点的上一个 相同值的链接节点 + # 递归,寻找改节点的下一个 相同值的链接节点 treeNode = treeNode.nodeLink # print treeNode return condPats