mirror of
https://github.com/apachecn/ailearning.git
synced 2026-02-08 21:04:33 +08:00
11、Aoriori
This commit is contained in:
12
src/python/12.FrequentPattemTree/apriori.py
Normal file
12
src/python/12.FrequentPattemTree/apriori.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def loadDataSet():
|
||||
return [[1,3,4],[2,3,5],[1,2,3,5],[2,5]]
|
||||
def createC1(dataSet):
|
||||
c1=[]
|
||||
for transaction in dataSet:
|
||||
for item in transaction:
|
||||
if not [item] in c1:
|
||||
c1.append([item])
|
||||
c1.sort()
|
||||
return map(frozenset,c1)
|
||||
def scanD(D,ck,minSupport):
|
||||
ssCnt = {}
|
||||
19
src/python/12.FrequentPattemTree/fpGrowth.py
Normal file
19
src/python/12.FrequentPattemTree/fpGrowth.py
Normal file
@@ -0,0 +1,19 @@
|
||||
class treeNode:
|
||||
def __init__(self,nameValue,numOccur,parentNode):
|
||||
self.name = nameValue
|
||||
self.count = numOccur
|
||||
self.nodeLink = None
|
||||
self.parent = parentNode
|
||||
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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import fpGrowth
|
||||
rootNode = fpGrowth.treeNode('pyramid',9,None)
|
||||
rootNode.children['eye']=fpGrowth.treeNode('eye',13,None)
|
||||
rootNode.disp()
|
||||
5
src/python/12.FrequentPattemTree/test.py
Normal file
5
src/python/12.FrequentPattemTree/test.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class Test:
|
||||
if __name__ == "__main__":
|
||||
fza=frozenset(['a','bc'])
|
||||
adict={fza:1,'b':2}
|
||||
print(adict)
|
||||
Reference in New Issue
Block a user