【问题标题】:How to make Apyori generate rules larger than 2 items?如何让 Apyori 生成大于 2 个项目的规则?
【发布时间】:2022-01-05 12:41:52
【问题描述】:

我一直在尝试在数据集上运行 apriori 并且它一直在工作。但是,我无法生成大于 2 的规则。我看到多个帖子说我可以更改 min_length 参数以增加规则的最小长度,但它似乎对我不起作用,而且我没有甚至在 apyori 文件中看到一个 min_length 参数。在这个 github 中有一个如何在 Python 中使用 apyori 的示例,其中还提到了 min_length 参数,但它设置为 2 并且尝试在笔记本中更改它并没有改变任何东西。 https://github.com/AnaMakharadze/Recommendation-Systems

【问题讨论】:

    标签: python apriori


    【解决方案1】:

    根据this SO answer,apriori算法中没有min_length关键字,但其实现方式不会报错。

    迭代项目可能是您正在寻找的替代方案:

    records = []
    # items_col contains list of ids etc.
    # example: [6500912, 6500695, 6500695, 6500695, 6500695]
    for items in df['items_col']:
        uniq_items = list(set(products))
        if (len(uniq_items) > 1):
            records.append([str(j) for j in uniq_products])
    
    rules = apriori(records, min_lift=lift_value, min_support=support_value)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-02
      • 2021-04-26
      • 1970-01-01
      • 2013-04-30
      • 2010-12-23
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      相关资源
      最近更新 更多