資源簡介
基于《機(jī)器學(xué)習(xí)實(shí)戰(zhàn)》中FP-Growth的代碼修改形成的頻繁項(xiàng)集挖掘函數(shù)FP_Growth(),可顯示各頻繁項(xiàng)集的支持度;同時(shí),還包括關(guān)聯(lián)規(guī)則發(fā)現(xiàn)函數(shù)findRules()。
代碼片段和文件信息
class?treeNode:
????def?__init__(self?nameValue?numOccur?parentNode):
????????self.name?=?nameValue
????????self.count?=?numOccur
????????self.nodelink?=?None
????????self.parent?=?parentNode??????#needs?to?be?updated
????????self.children?=?{}?
????
????def?inc(self?numOccur):
????????self.count?+=?numOccur
????????
????def?disp(self?ind=1):
????????print(‘??‘*ind?self.name?‘?‘?self.count)
????????for?child?in?self.children.values():
????????????child.disp(ind+1)
def?createTree(dataSet?minSup=1):?#create?FP-tree?from?dataset?but?don‘t?mine
????headerTable?=?{}
????#go?over?dataSet?twice
????for?trans?in?dataSet:#first?pass?counts?frequency?of?occurance
????????for?item?in?trans:
????????????headerTable[item]?=?headerTable.get(item?0)?+?dataSet[trans]
????f
評(píng)論
共有 條評(píng)論