機器學習實戰——使用FP-growth演算法來發現頻繁集
阿新 • • 發佈:2018-12-17
問題:RuntimeError: dictionary changed size during iteration
#問題程式碼
for k in headerTable.keys():
if headerTable[k]< minSup:
del(headerTable[k])
#修改+list()
for k in list(headerTable.keys()):
if headerTable[k]< minSup:
del(headerTable[k])
字典在遍歷時不能進行修改,建議轉成列表或集合處理。
問題:AttributeError: 'str' object has no attribute 'inc'
#問題程式碼
if items[0] in inTree.children:
inTree.children[items[0].inc(count)]
# 為[]位置標錯
if items[0] in inTree.children:
inTree.children[items[0]].inc(count)
問題:TypeError: '<' not supported between instances of 'treeNode' and 'treeNode'
#修改前
bigL = [v[0] for v in sorted(headerTable.items(),key = lambda p: p[1])]
#修改後
bigL = [v[0] for v in sorted(headerTable.items(), key=lambda p: str(p[1]))]