尝试实现Apriori算法并成功提取在所有交易中一起出现的子集。以下是我的代码:
例如
我尝试使用:
但是它会生成以下错误信息:
有什么想法吗?
subsets = [set(['Breakfast & Brunch', 'Restaurants']), set(['American (Traditional)', 'Breakfast & Brunch']), set(['American (Traditional)', 'Restaurants']), set(['American (Traditional)', 'Breakfast & Brunch']), set(['Breakfast & Brunch', 'Restaurants']), set(['American (Traditional)', 'Restaurants'])]
例如
set(['早餐和早午餐','餐厅'])
出现两次,我需要跟踪出现次数以及相应模式。我尝试使用:
from collections import Counter
support_set = Counter()
# some code that generated the list above
support_set.update(subsets)
但是它会生成以下错误信息:
supported = itemsets_support(transactions, candidates)
File "apriori.py", line 77, in itemsets_support
support_set.update(subsets)
File"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/collections.py", line 567, in update
self[elem] = self_get(elem, 0) + 1
TypeError: unhashable type: 'set'
有什么想法吗?
arules
包。将所有内容放入Counter
中无法扩展。请尝试使用超市数据集等其他数据集。 - Has QUIT--Anony-Mousse