首页 > 解决方案 > 使用 Python mlxtend 的关联规则

问题描述

我有一个数据列表,我想在其中找到关联。我发现频繁项集使用 -

frequent_itemsets = apriori(df, min_support=0.01, use_colnames=True)

这给出了频繁项集 -

        support  itemsets
0      0.020438  [AUCKLAND]
1      0.015320  [Adelaide]
2      0.043066  [Auckland]
....

我需要找到信心。我已将关联规则功能用作-

aa = association_rules(frequent_itemsets, metric="confidence", min_threshold=0.001)

但是有了这个,我得到了一个只有列名的空白表。

标签: pythonpython-3.x

解决方案


records = []
for i in range(0, 7501):
records.append([str(store_data.values[i,j]) for j in range(0, 20)]) association_rules = apriori(records, min_support=0.0045, min_confidence=0.2, min_lift=3, min_length=2)

我认为你的代码应该是这样的,你不应该在关联规则的情况下传递frequent_itemsets,因为它单独适用于你的数据,而不是你应该使用附加的名称,因为我在我的案例中使用了记录。我希望你能有所了解。


推荐阅读