发现频繁项集FP-growth算法

              FP-growth算法只需要对数据库进行两次扫描,而Apriori算法对于每个潜在的频繁项集都会扫描数据集判断给定模式是否频繁,因此FP-growth算法的速度要比Apriori算法快。在小规模数据集上,这不是什么问题,但当处理更大数据集时,就会产生较大问题,但是FP-growth不能发现关联规则。

              发现频繁项集过程:(1)构建FP树(2)从FP树中挖掘频繁项集

              优点:一般要快于Apriori。缺点:实现比较困难,在某些数据集上性能会下降。适用数据类型:标称型数据。

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 # blank sum  ' '*ind ' '
        for child in self.children.values():
            child.disp(ind+1)
FP-growth树节点的数据结构

你可能感兴趣的:(机器学习)