機器學習實戰——使用FP-growth算法來發現頻繁集

問題: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]))]

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章