开始使用免费开始使用

生成关联规则

在上一节的最后一个练习中,您使用 Apriori 算法为创意礼品店店主计算了频繁项集。您告诉店主:将 support 从 0.005 放宽到 0.003,项集数量从 9 增加到 91;再次放宽到 0.001,数量增加到 429。店经理对您完成的描述性分析很满意,现在请您从之前计算出的两组频繁项集中识别一些关联规则。

注意,pandas 已按 pd 导入,且两组频繁项集已分别存为 frequent_itemset_1frequent_itemset_2。您的目标是确定可以从这些项集中挖掘出哪些关联规则。

本练习是课程的一部分

Python 中的购物篮分析

查看课程

练习说明

  • mlxtend 中导入可根据 apriori 结果计算关联规则的算法。
  • 使用 support 作为度量、阈值为 0.0015,完成对 frequent_itemsets_1 计算关联规则的语句。
  • 使用 support 作为度量、阈值为 0.0015,完成对 frequent_itemsets_2 计算关联规则的语句。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import the association rule function from mlxtend
from mlxtend.____ import ____

# Compute all association rules for frequent_itemsets_1
rules_1 = association_rules(frequent_itemsets_1, 
                            metric = "____", 
                         	min_threshold = ____)

# Compute all association rules for frequent_itemsets_2
rules_2 = association_rules(frequent_itemsets_2, 
                            metric = ____, 
                        	____)

# Print the number of association rules generated
print(len(rules_1), len(rules_2))
编辑并运行代码