【发布时间】:2022-01-14 22:36:54
【问题描述】:
我在 java 中有一个包含杂货的 List 列表。我想执行一个篮子分析,所以我找到了一个 python 实现。但我不知道如何从这个页面转换以下代码:Apriori-association-rule-explained
我的 python 不是很好,所以我需要一些建议如何将此代码从 Python 转换为 Java:
def apriori(itemSetList, minSup, minConf):
C1ItemSet = getItemSetFromList(itemSetList)
# Final result, global frequent itemset
globalFreqItemSet = dict()
# Storing global itemset with support count
globalItemSetWithSup = defaultdict(int)
L1ItemSet = getAboveMinSup(C1ItemSet, itemSetList, minSup, globalItemSetWithSup)
currentLSet = L1ItemSet
k = 2
# Calculating frequent item set
while(currentLSet):
# Storing frequent itemset
globalFreqItemSet[k-1] = currentLSet
# Self-joining Lk
candidateSet = getUnion(currentLSet, k)
# Perform subset testing and remove pruned supersets
candidateSet = pruning(candidateSet, currentLSet, k-1)
# Scanning itemSet for counting support
currentLSet = getAboveMinSup(candidateSet, itemSetList, minSup, globalItemSetWithSup)
k += 1
rules = associationRule(globalFreqItemSet, globalItemSetWithSup, minConf)
rules.sort(key=lambda x: x[2])
return globalFreqItemSet, rules
【问题讨论】: