【问题标题】:How do I convert apriori algorithm from python to java?如何将 apriori 算法从 python 转换为 java?
【发布时间】: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

【问题讨论】:

    标签: python java apriori


    【解决方案1】:

    逻辑保持不变。 只需尝试阅读 java 文档并弄清楚如何实现循环和您需要的东西。 这不是太难。 你能行的! 万事如意!

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多