聚合与筛选
在视频中,我们帮助一家礼品店的经理根据关联规则来安排其线下门店的分区。由于门店布局的限制,我们需要把分区按两两成组进行摆放。应用高级筛选技术后,我们提出了下面的平面布局方案。
现在,店长请您基于不同的标准再给出一份平面布局提案:每一对分区应包含一个高支持度商品与一个低支持度商品。数据集 aggregated 已为您完成聚合并进行了独热编码。此外,mlxtend 中的 apriori() 和 association_rules() 已经导入。
本练习是课程的一部分
Python 中的购物篮分析
练习说明
- 以 0.0001 作为最小支持度阈值生成频繁项集。
- 识别所有最小支持度阈值为 0.0001 的规则。
- 选择所有前件支持度(antecedent support)大于 0.35 的规则。
- 选择所有结果件支持度(consequent support)上限低于 0.35 的规则。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Apply the apriori algorithm with a minimum support of 0.0001
frequent_itemsets = apriori(aggregated, ____, use_colnames = True)
# Generate the initial set of rules using a minimum support of 0.0001
rules = association_rules(frequent_itemsets,
metric = "____", min_threshold = ____)
# Set minimum antecedent support to 0.35
rules = rules[____['antecedent support'] > ____]
# Set maximum consequent support to 0.35
rules = rules[____ < 0.35]
# Print the remaining rules
print(rules)