0

The apriori algorithom

def aprioriGen(Lk, k): #creates Ck
    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]
            L1.sort(); L2.sort()
            if L1==L2: #if first k-2 elements are equal
                retList.append(Lk[i] | Lk[j]) #set union
    return retList

l3 = [frozenset([0, 1, 2]), frozenset([0, 1, 3]), frozenset([1, 2, 4])] 
l4 = aprioriGen(l3, 4) 
print l4 

the result is :[frozenset([0, 1, 2, 3])],

the algorithm is right? why [frozenset([0, 1, 2, 4])] not including?

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
salmon
  • 1
  • 1
  • Possible duplicate of [Apriori Algorithm](http://stackoverflow.com/questions/1248373/apriori-algorithm) – Abhijeet Feb 28 '16 at 05:17
  • @Abhijeet thanks, i understand apriori, but i am not understand the reason of : if L1==L2: #if first k-2 elements are equal – salmon Feb 29 '16 at 01:09

0 Answers0