使用平行坐标可视化规则
在上一个练习中的可视化演示,让创始人相信"支持度-置信度边界"值得进一步探索。她现在建议提取该边界的一部分并将其可视化。由于落在该边界上的规则在大多数常见指标上都很强,她认为与其根据某个指标显示强度,不如直接展示规则是否存在。
您意识到,平行坐标图非常适合这种情况。数据已作为 onehot 导入。同时,apriori()、association_rules() 和 parallel_coordinates() 也已导入,pandas 可用名为 pd。函数 rules_to_coordinates() 已定义并可直接使用。
本练习是课程的一部分
Python 中的购物篮分析
练习说明
- 以最小支持度 0.05 完成 Apriori 算法语句。
- 以最小置信度阈值 0.50 计算关联规则。该阈值足够高,只会捕捉靠近支持度-置信度边界上部的点。
- 将规则转换为坐标。
- 使用
parallel_coordinates()绘制这些坐标。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Compute the frequent itemsets
frequent_itemsets = ____(onehot, min_support = ____,
use_colnames = True, max_len = 2)
# Compute rules from the frequent itemsets with the confidence metric
rules = association_rules(frequent_itemsets, metric = '____',
min_threshold = 0.50)
# Convert rules into coordinates suitable for use in a parallel coordinates plot
coords = rules_to_coordinates(____)
# Generate parallel coordinates plot
parallel_coordinates(____, 'rule')
plt.legend([])
plt.show()