Error message here!

Hide Error message here!

Error message here!

Hide Error message here!

Error message here!

Close

# Python两步实现关联规则Apriori算法，参考机器学习实战，包括频繁项集的构建以及关联规则的挖掘

Laurel1115 2019-02-22 10:47:00 阅读数:249 评论数:0 点赞数:0 收藏数:0

In [122]:

from numpy import /* def loadDataSet(): return [[1, 3, 4,6,7], [2, 3, 4,5,6,7], [1, 2, 3, 5,7], [2,4, 5,6],[3,4,5,6,7]] 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)/#use frozen set so we can use it as a key in a dict def scanD(D, Ck, minSupport): ssCnt = {} for tid in D: for can in Ck: if can.issubset(tid): if not ssCnt.has_key(can): ssCnt[can]=1 else: ssCnt[can] += 1 numItems = float(len(D)) retList = [] supportData = {} for key in ssCnt: support = ssCnt[key]/numItems if support >= minSupport: retList.insert(0,key) supportData[key] = support return retList, supportData def aprioriGen(Lk, k): /#creates Ck print'Lk:',Lk retList = [] lenLk = len(Lk) for i in range(lenLk): for j in range(i+1, lenLk): L1 = list(Lk[i])[:k-2]; L2 = list(Lk[j])[:k-2]/#见《数据挖掘概念与技术》p161的连接步讲解 L1.sort(); L2.sort() print'L1,L2',L1,L2 if L1==L2: /#if first k-2 elements are equal，另外在由一项频繁集L1构造C2时，以上[:k-2]=[:0]=[],所以会有L1==L2,构造出2项候选集C2 retList.append(Lk[i] | Lk[j]) /#set union return retList def apriori(dataSet, minSupport = 0.5): C1 = createC1(dataSet) D = map(set, dataSet) L1, supportData = scanD(D, C1, minSupport) L = [L1] k = 2 while (len(L[k-2]) > 0): Ck = aprioriGen(L[k-2], k) Lk, supK = scanD(D, Ck, minSupport)/#scan DB to get Lk supportData.update(supK) L.append(Lk) k += 1 return L, supportData

In [130]:

data=loadDataSet() D=map(set,data) C1=createC1(D) L,suppData=apriori(data,0.5) print 'C1:',C1 print 'L:',L print 'suppData:',suppData

Lk: [frozenset([2]), frozenset([4]), frozenset([6]), frozenset([3]), frozenset([5]), frozenset([7])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Lk: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] L1,L2 [2] [4] L1,L2 [2] [4] L1,L2 [2] [4] L1,L2 [2] [3] L1,L2 [2] [3] L1,L2 [2] [6] L1,L2 [2] [5] L1,L2 [2] [3] L1,L2 [2] [3] L1,L2 [2] [5] L1,L2 [4] [4] L1,L2 [4] [4] L1,L2 [4] [3] L1,L2 [4] [3] L1,L2 [4] [6] L1,L2 [4] [5] L1,L2 [4] [3] L1,L2 [4] [3] L1,L2 [4] [5] L1,L2 [4] [4] L1,L2 [4] [3] L1,L2 [4] [3] L1,L2 [4] [6] L1,L2 [4] [5] L1,L2 [4] [3] L1,L2 [4] [3] L1,L2 [4] [5] L1,L2 [4] [3] L1,L2 [4] [3] L1,L2 [4] [6] L1,L2 [4] [5] L1,L2 [4] [3] L1,L2 [4] [3] L1,L2 [4] [5] L1,L2 [3] [3] L1,L2 [3] [6] L1,L2 [3] [5] L1,L2 [3] [3] L1,L2 [3] [3] L1,L2 [3] [5] L1,L2 [3] [6] L1,L2 [3] [5] L1,L2 [3] [3] L1,L2 [3] [3] L1,L2 [3] [5] L1,L2 [6] [5] L1,L2 [6] [3] L1,L2 [6] [3] L1,L2 [6] [5] L1,L2 [5] [3] L1,L2 [5] [3] L1,L2 [5] [5] L1,L2 [3] [3] L1,L2 [3] [5] L1,L2 [3] [5] Lk: [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])] L1,L2 [3, 6] [4, 5] L1,L2 [3, 6] [3, 5] L1,L2 [3, 6] [3, 4] L1,L2 [3, 6] [4, 6] L1,L2 [3, 6] [3, 4] L1,L2 [4, 5] [3, 5] L1,L2 [4, 5] [3, 4] L1,L2 [4, 5] [4, 6] L1,L2 [4, 5] [3, 4] L1,L2 [3, 5] [3, 4] L1,L2 [3, 5] [4, 6] L1,L2 [3, 5] [3, 4] L1,L2 [3, 4] [4, 6] L1,L2 [3, 4] [3, 4] L1,L2 [4, 6] [3, 4] Lk: [frozenset([3, 4, 6, 7])] C1: [frozenset([1]), frozenset([2]), frozenset([3]), frozenset([4]), frozenset([5]), frozenset([6]), frozenset([7])] L: [[frozenset([2]), frozenset([4]), frozenset([6]), frozenset([3]), frozenset([5]), frozenset([7])], [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])], [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])], [frozenset([3, 4, 6, 7])], []] suppData: {frozenset([5, 7]): 0.6, frozenset([3, 4, 6]): 0.6, frozenset([3, 7]): 0.8, frozenset([4, 6, 7]): 0.6, frozenset([3, 6]): 0.6, frozenset([3, 4, 7]): 0.6, frozenset([5, 6]): 0.6, frozenset([2, 6]): 0.4, frozenset([6, 7]): 0.6, frozenset([3, 5, 7]): 0.6, frozenset([4, 5, 6]): 0.6, frozenset([4]): 0.8, frozenset([4, 7]): 0.6, frozenset([2, 7]): 0.4, frozenset([2, 4]): 0.4, frozenset([7]): 0.8, frozenset([5]): 0.8, frozenset([3]): 0.8, frozenset([3, 4, 5]): 0.4, frozenset([6]): 0.8, frozenset([3, 5, 6]): 0.4, frozenset([3, 5]): 0.6, frozenset([5, 6, 7]): 0.4, frozenset([3, 4]): 0.6, frozenset([3, 6, 7]): 0.6, frozenset([2, 3]): 0.4, frozenset([4, 6]): 0.8, frozenset([2, 5]): 0.6, frozenset([1]): 0.4, frozenset([4, 5, 7]): 0.4, frozenset([2]): 0.6, frozenset([3, 4, 6, 7]): 0.6, frozenset([4, 5]): 0.6}二、基于构造出的频繁项集挖掘关联规则（注释都在代码中了～。～） 需要注意的就是对rulesFromConseq()函数的理解，可以参照我代码中添加的用于测试的输出函数的输出理解

In [123]:

def generateRules(L, supportData, minConf=0.7): /#supportData is a dict coming from scanD bigRuleList = [] for i in range(1, len(L)):/#only get the sets with two or more items print 'i:',i for freqSet in L[i]: print'L[i]:',L[i] print'freqSet:',freqSet H1 = [frozenset([item]) for item in freqSet] print 'H1:',H1 if (i > 1): rulesFromConseq(freqSet, H1, supportData, bigRuleList, minConf) else: calcConf(freqSet, H1, supportData, bigRuleList, minConf) return bigRuleList def calcConf(freqSet, H, supportData, brl, minConf=0.7): prunedH = [] /#create new list to return for conseq in H: print'conseq:',conseq print'freqSet-conseq:',freqSet-conseq conf = supportData[freqSet]/supportData[freqSet-conseq] /#calc confidence if conf >= minConf: print freqSet-conseq,'-->',conseq,'conf:',conf brl.append((freqSet-conseq, conseq, conf)) prunedH.append(conseq) /# print 'prunedH:',prunedH return prunedH /#rulesFromConseq目的就是对每一个频繁项集生成右边的规则，一个频繁项集可以生成很多右边的规则 /#if (len(freqSet) > (m + 1))这是迭代停止的条件，也就是当右边的规则的元素数+1=该频繁项长度时停止迭代 /#if (len(Hmp1) > 1)当Hmp1的长度大于1时才能合并，合并需要至少两个frozenset def rulesFromConseq(freqSet, H, supportData, brl, minConf=0.7): m = len(H[0]) print'm:',m print'len(freqSet):',len(freqSet) if (len(freqSet) > (m + 1)): /#try further merging Hmp1 = aprioriGen(H, m+1)/#create Hm+1 new candidates print'Hmp1:',Hmp1 Hmp1 = calcConf(freqSet, Hmp1, supportData, brl, minConf) print 'Hmp2:',Hmp1 if (len(Hmp1) > 1): /#need at least two sets to merge print'---------' rulesFromConseq(freqSet, Hmp1, supportData, brl, minConf) print'/*/*/*/*/*/*/*/*/*'

In [131]:

generateRules(L,suppData,0.5)

i: 1 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([2, 5]) H1: [frozenset([2]), frozenset([5])] conseq: frozenset([2]) freqSet-conseq: frozenset([5]) frozenset([5]) --> frozenset([2]) conf: 0.75 conseq: frozenset([5]) freqSet-conseq: frozenset([2]) frozenset([2]) --> frozenset([5]) conf: 1.0 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([4, 5]) H1: [frozenset([4]), frozenset([5])] conseq: frozenset([4]) freqSet-conseq: frozenset([5]) frozenset([5]) --> frozenset([4]) conf: 0.75 conseq: frozenset([5]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([5]) conf: 0.75 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([4, 7]) H1: [frozenset([4]), frozenset([7])] conseq: frozenset([4]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([4]) conf: 0.75 conseq: frozenset([7]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([7]) conf: 0.75 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([4, 6]) H1: [frozenset([4]), frozenset([6])] conseq: frozenset([4]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([4]) conf: 1.0 conseq: frozenset([6]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([6]) conf: 1.0 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([3, 4]) H1: [frozenset([3]), frozenset([4])] conseq: frozenset([3]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([3]) conf: 0.75 conseq: frozenset([4]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([4]) conf: 0.75 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([3, 5]) H1: [frozenset([3]), frozenset([5])] conseq: frozenset([3]) freqSet-conseq: frozenset([5]) frozenset([5]) --> frozenset([3]) conf: 0.75 conseq: frozenset([5]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([5]) conf: 0.75 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([6, 7]) H1: [frozenset([6]), frozenset([7])] conseq: frozenset([6]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([6]) conf: 0.75 conseq: frozenset([7]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([7]) conf: 0.75 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([5, 6]) H1: [frozenset([5]), frozenset([6])] conseq: frozenset([5]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([5]) conf: 0.75 conseq: frozenset([6]) freqSet-conseq: frozenset([5]) frozenset([5]) --> frozenset([6]) conf: 0.75 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([3, 6]) H1: [frozenset([3]), frozenset([6])] conseq: frozenset([3]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([3]) conf: 0.75 conseq: frozenset([6]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([6]) conf: 0.75 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([3, 7]) H1: [frozenset([3]), frozenset([7])] conseq: frozenset([3]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([3]) conf: 1.0 conseq: frozenset([7]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([7]) conf: 1.0 L[i]: [frozenset([2, 5]), frozenset([4, 5]), frozenset([4, 7]), frozenset([4, 6]), frozenset([3, 4]), frozenset([3, 5]), frozenset([6, 7]), frozenset([5, 6]), frozenset([3, 6]), frozenset([3, 7]), frozenset([5, 7])] freqSet: frozenset([5, 7]) H1: [frozenset([5]), frozenset([7])] conseq: frozenset([5]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([5]) conf: 0.75 conseq: frozenset([7]) freqSet-conseq: frozenset([5]) frozenset([5]) --> frozenset([7]) conf: 0.75 i: 2 L[i]: [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])] freqSet: frozenset([3, 6, 7]) H1: [frozenset([3]), frozenset([6]), frozenset([7])] m: 1 len(freqSet): 3 Lk: [frozenset([3]), frozenset([6]), frozenset([7])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Hmp1: [frozenset([3, 6]), frozenset([3, 7]), frozenset([6, 7])] conseq: frozenset([3, 6]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([3, 6]) conf: 0.75 conseq: frozenset([3, 7]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([3, 7]) conf: 0.75 conseq: frozenset([6, 7]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([6, 7]) conf: 0.75 Hmp2: [frozenset([3, 6]), frozenset([3, 7]), frozenset([6, 7])] --------- m: 2 len(freqSet): 3 /*/*/*/*/*/*/*/*/* L[i]: [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])] freqSet: frozenset([4, 5, 6]) H1: [frozenset([4]), frozenset([5]), frozenset([6])] m: 1 len(freqSet): 3 Lk: [frozenset([4]), frozenset([5]), frozenset([6])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Hmp1: [frozenset([4, 5]), frozenset([4, 6]), frozenset([5, 6])] conseq: frozenset([4, 5]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([4, 5]) conf: 0.75 conseq: frozenset([4, 6]) freqSet-conseq: frozenset([5]) frozenset([5]) --> frozenset([4, 6]) conf: 0.75 conseq: frozenset([5, 6]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([5, 6]) conf: 0.75 Hmp2: [frozenset([4, 5]), frozenset([4, 6]), frozenset([5, 6])] --------- m: 2 len(freqSet): 3 /*/*/*/*/*/*/*/*/* L[i]: [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])] freqSet: frozenset([3, 5, 7]) H1: [frozenset([3]), frozenset([5]), frozenset([7])] m: 1 len(freqSet): 3 Lk: [frozenset([3]), frozenset([5]), frozenset([7])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Hmp1: [frozenset([3, 5]), frozenset([3, 7]), frozenset([5, 7])] conseq: frozenset([3, 5]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([3, 5]) conf: 0.75 conseq: frozenset([3, 7]) freqSet-conseq: frozenset([5]) frozenset([5]) --> frozenset([3, 7]) conf: 0.75 conseq: frozenset([5, 7]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([5, 7]) conf: 0.75 Hmp2: [frozenset([3, 5]), frozenset([3, 7]), frozenset([5, 7])] --------- m: 2 len(freqSet): 3 /*/*/*/*/*/*/*/*/* L[i]: [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])] freqSet: frozenset([3, 4, 7]) H1: [frozenset([3]), frozenset([4]), frozenset([7])] m: 1 len(freqSet): 3 Lk: [frozenset([3]), frozenset([4]), frozenset([7])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Hmp1: [frozenset([3, 4]), frozenset([3, 7]), frozenset([4, 7])] conseq: frozenset([3, 4]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([3, 4]) conf: 0.75 conseq: frozenset([3, 7]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([3, 7]) conf: 0.75 conseq: frozenset([4, 7]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([4, 7]) conf: 0.75 Hmp2: [frozenset([3, 4]), frozenset([3, 7]), frozenset([4, 7])] --------- m: 2 len(freqSet): 3 /*/*/*/*/*/*/*/*/* L[i]: [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])] freqSet: frozenset([4, 6, 7]) H1: [frozenset([4]), frozenset([6]), frozenset([7])] m: 1 len(freqSet): 3 Lk: [frozenset([4]), frozenset([6]), frozenset([7])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Hmp1: [frozenset([4, 6]), frozenset([4, 7]), frozenset([6, 7])] conseq: frozenset([4, 6]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([4, 6]) conf: 0.75 conseq: frozenset([4, 7]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([4, 7]) conf: 0.75 conseq: frozenset([6, 7]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([6, 7]) conf: 0.75 Hmp2: [frozenset([4, 6]), frozenset([4, 7]), frozenset([6, 7])] --------- m: 2 len(freqSet): 3 /*/*/*/*/*/*/*/*/* L[i]: [frozenset([3, 6, 7]), frozenset([4, 5, 6]), frozenset([3, 5, 7]), frozenset([3, 4, 7]), frozenset([4, 6, 7]), frozenset([3, 4, 6])] freqSet: frozenset([3, 4, 6]) H1: [frozenset([3]), frozenset([4]), frozenset([6])] m: 1 len(freqSet): 3 Lk: [frozenset([3]), frozenset([4]), frozenset([6])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Hmp1: [frozenset([3, 4]), frozenset([3, 6]), frozenset([4, 6])] conseq: frozenset([3, 4]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([3, 4]) conf: 0.75 conseq: frozenset([3, 6]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([3, 6]) conf: 0.75 conseq: frozenset([4, 6]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([4, 6]) conf: 0.75 Hmp2: [frozenset([3, 4]), frozenset([3, 6]), frozenset([4, 6])] --------- m: 2 len(freqSet): 3 /*/*/*/*/*/*/*/*/* i: 3 L[i]: [frozenset([3, 4, 6, 7])] freqSet: frozenset([3, 4, 6, 7]) H1: [frozenset([3]), frozenset([4]), frozenset([6]), frozenset([7])] m: 1 len(freqSet): 4 Lk: [frozenset([3]), frozenset([4]), frozenset([6]), frozenset([7])] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] L1,L2 [] [] Hmp1: [frozenset([3, 4]), frozenset([3, 6]), frozenset([3, 7]), frozenset([4, 6]), frozenset([4, 7]), frozenset([6, 7])] conseq: frozenset([3, 4]) freqSet-conseq: frozenset([6, 7]) frozenset([6, 7]) --> frozenset([3, 4]) conf: 1.0 conseq: frozenset([3, 6]) freqSet-conseq: frozenset([4, 7]) frozenset([4, 7]) --> frozenset([3, 6]) conf: 1.0 conseq: frozenset([3, 7]) freqSet-conseq: frozenset([4, 6]) frozenset([4, 6]) --> frozenset([3, 7]) conf: 0.75 conseq: frozenset([4, 6]) freqSet-conseq: frozenset([3, 7]) frozenset([3, 7]) --> frozenset([4, 6]) conf: 0.75 conseq: frozenset([4, 7]) freqSet-conseq: frozenset([3, 6]) frozenset([3, 6]) --> frozenset([4, 7]) conf: 1.0 conseq: frozenset([6, 7]) freqSet-conseq: frozenset([3, 4]) frozenset([3, 4]) --> frozenset([6, 7]) conf: 1.0 Hmp2: [frozenset([3, 4]), frozenset([3, 6]), frozenset([3, 7]), frozenset([4, 6]), frozenset([4, 7]), frozenset([6, 7])] --------- m: 2 len(freqSet): 4 Lk: [frozenset([3, 4]), frozenset([3, 6]), frozenset([3, 7]), frozenset([4, 6]), frozenset([4, 7]), frozenset([6, 7])] L1,L2 [3] [3] L1,L2 [3] [3] L1,L2 [3] [4] L1,L2 [3] [4] L1,L2 [3] [6] L1,L2 [3] [3] L1,L2 [3] [4] L1,L2 [3] [4] L1,L2 [3] [6] L1,L2 [3] [4] L1,L2 [3] [4] L1,L2 [3] [6] L1,L2 [4] [4] L1,L2 [4] [6] L1,L2 [4] [6] Hmp1: [frozenset([3, 4, 6]), frozenset([3, 4, 7]), frozenset([3, 6, 7]), frozenset([4, 6, 7])] conseq: frozenset([3, 4, 6]) freqSet-conseq: frozenset([7]) frozenset([7]) --> frozenset([3, 4, 6]) conf: 0.75 conseq: frozenset([3, 4, 7]) freqSet-conseq: frozenset([6]) frozenset([6]) --> frozenset([3, 4, 7]) conf: 0.75 conseq: frozenset([3, 6, 7]) freqSet-conseq: frozenset([4]) frozenset([4]) --> frozenset([3, 6, 7]) conf: 0.75 conseq: frozenset([4, 6, 7]) freqSet-conseq: frozenset([3]) frozenset([3]) --> frozenset([4, 6, 7]) conf: 0.75 Hmp2: [frozenset([3, 4, 6]), frozenset([3, 4, 7]), frozenset([3, 6, 7]), frozenset([4, 6, 7])] --------- m: 3 len(freqSet): 4 /*/*/*/*/*/*/*/*/* /*/*/*/*/*/*/*/*/* i: 4

Out[131]:

[(frozenset({5}), frozenset({2}), 0.7499999999999999), (frozenset({2}), frozenset({5}), 1.0), (frozenset({5}), frozenset({4}), 0.7499999999999999), (frozenset({4}), frozenset({5}), 0.7499999999999999), (frozenset({7}), frozenset({4}), 0.7499999999999999), (frozenset({4}), frozenset({7}), 0.7499999999999999), (frozenset({6}), frozenset({4}), 1.0), (frozenset({4}), frozenset({6}), 1.0), (frozenset({4}), frozenset({3}), 0.7499999999999999), (frozenset({3}), frozenset({4}), 0.7499999999999999), (frozenset({5}), frozenset({3}), 0.7499999999999999), (frozenset({3}), frozenset({5}), 0.7499999999999999), (frozenset({7}), frozenset({6}), 0.7499999999999999), (frozenset({6}), frozenset({7}), 0.7499999999999999), (frozenset({6}), frozenset({5}), 0.7499999999999999), (frozenset({5}), frozenset({6}), 0.7499999999999999), (frozenset({6}), frozenset({3}), 0.7499999999999999), (frozenset({3}), frozenset({6}), 0.7499999999999999), (frozenset({7}), frozenset({3}), 1.0), (frozenset({3}), frozenset({7}), 1.0), (frozenset({7}), frozenset({5}), 0.7499999999999999), (frozenset({5}), frozenset({7}), 0.7499999999999999), (frozenset({7}), frozenset({3, 6}), 0.7499999999999999), (frozenset({6}), frozenset({3, 7}), 0.7499999999999999), (frozenset({3}), frozenset({6, 7}), 0.7499999999999999), (frozenset({6}), frozenset({4, 5}), 0.7499999999999999), (frozenset({5}), frozenset({4, 6}), 0.7499999999999999), (frozenset({4}), frozenset({5, 6}), 0.7499999999999999), (frozenset({7}), frozenset({3, 5}), 0.7499999999999999), (frozenset({5}), frozenset({3, 7}), 0.7499999999999999), (frozenset({3}), frozenset({5, 7}), 0.7499999999999999), (frozenset({7}), frozenset({3, 4}), 0.7499999999999999), (frozenset({4}), frozenset({3, 7}), 0.7499999999999999), (frozenset({3}), frozenset({4, 7}), 0.7499999999999999), (frozenset({7}), frozenset({4, 6}), 0.7499999999999999), (frozenset({6}), frozenset({4, 7}), 0.7499999999999999), (frozenset({4}), frozenset({6, 7}), 0.7499999999999999), (frozenset({6}), frozenset({3, 4}), 0.7499999999999999), (frozenset({4}), frozenset({3, 6}), 0.7499999999999999), (frozenset({3}), frozenset({4, 6}), 0.7499999999999999), (frozenset({6, 7}), frozenset({3, 4}), 1.0), (frozenset({4, 7}), frozenset({3, 6}), 1.0), (frozenset({4, 6}), frozenset({3, 7}), 0.7499999999999999), (frozenset({3, 7}), frozenset({4, 6}), 0.7499999999999999), (frozenset({3, 6}), frozenset({4, 7}), 1.0), (frozenset({3, 4}), frozenset({6, 7}), 1.0), (frozenset({7}), frozenset({3, 4, 6}), 0.7499999999999999), (frozenset({6}), frozenset({3, 4, 7}), 0.7499999999999999), (frozenset({4}), frozenset({3, 6, 7}), 0.7499999999999999), (frozenset({3}), frozenset({4, 6, 7}), 0.7499999999999999)]

https://www.cnblogs.com/lxy-fight/p/10416976.html

30万现金开奖等你来领