apriori algorithom in machine learning in action -
the apriori algorithom
def apriorigen(lk, k): #creates ck retlist = [] lenlk = len(lk) in range(lenlk): 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 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 :[frozenset([0, 1, 2, 3])],
the algorithm right? why [frozenset([0, 1, 2, 4])]
not including?
Comments
Post a Comment