开始使用免费开始使用

选择支持度阈值

在线礼品店的经理查看了您在上一个练习中给出的结果,并称赞了您的工作。不过,她也提出了一个问题:您识别出的所有项集都只包含一个商品。她询问是否可以放宽规则,生成更多的项集,最好还能包含多个商品的项集。

您同意后,开始思考为什么没有出现包含超过 1 个商品的项集。原因不可能是 max_len 参数,因为它被设置为 3。您判断问题在于支持度,并决定测试两个不同的取值,每次都检查会多生成多少项集。请注意,pandas 已以 pd 导入,且独热编码后的数据以 onehot 提供。

本练习是课程的一部分

Python 中的购物篮分析

查看课程

交互式实操练习

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

# Import apriori from mlxtend
from mlxtend.____ import ____

# Compute frequent itemsets using a support of 0.003 and length of 3
frequent_itemsets_1 = apriori(onehot, min_support = ____, 
                            max_len = ____, use_colnames = True)

# Compute frequent itemsets using a support of 0.001 and length of 3
frequent_itemsets_2 = apriori(onehot, min_support = ____, 
                            ____, use_colnames = True)

# Print the number of freqeuent itemsets
print(len(frequent_itemsets_1), len(frequent_itemsets_2))
编辑并运行代码