我有一个具有60万行和15列的csv文件“ Col1,Col2 … COl15”.我想生成关联规则,其中只有右侧只有col15中的值.我正在使用here的apriori实现
它以这种方式计算每个项目集的minSupport:
oneCSet = returnItemsWithMinSupport(itemSet,
transactionList,
minSupport,
freqSet)
print "reached line 80"
currentLSet = oneCSet
k = 2
while(currentLSet != set([])):
print k
largeSet[k-1] = currentLSet
currentLSet = joinSet(currentLSet, k)
currentCSet = returnItemsWithMinSupport(currentLSet,
transactionList,
minSupport,
freqSet)
currentLSet = currentCSet
k = k + 1
def returnItemsWithMinSupport(itemSet, transactionList, minSupport, freqSet):
"""calculates the support for items in the itemSet and returns a subset
of the itemSet each of whose elements satisfies the minimum support"""
_itemSet = set()
localSet = defaultdict(int)
#print itemSet
for item in itemSet:
#print "I am here", list(item)
for transaction in transactionList:
if item.issubset(transaction):
freqSet[item] += 1
localSet[item] += 1
print "Done half"
for item, count in localSet.items():
support = float(count)/len(transactionList)
if support >= minSupport:
_itemSet.add(item)
return _itemSet
但是对于我拥有的许多行,这将花费很多时间,因为我希望RHS被限制为仅具有特定列(Col15)中的值,所以我可以通过某种方式减少频繁使用的项目集来使实现更快?其他方法之一是最后过滤规则,但是时间复杂度相同.还是有其他一些实现/库可以帮助我加快速度?