资源简介

详解python实现FP-TREE进行关联规则挖掘 python3.2实现,可以生成每一步fp树的图片(需要安装PIL)

资源截图

代码片段和文件信息

__author__ = ‘wei‘

from fpnode import fpnode
from treebuilder import treebuilder

class cpbtreebuilder(treebuilder):
    def __init__(selfcpb):
        self.cpb=cpb
        self.items=self.getitems()
        self.itemtable=self.getitemtable()
        self.itemcount=self.getitemcount()
        self.tree=self.growtree()

    def getitems(self):
        items=[]
        for path in self.cpb:
            for node in path:
                if node[0] not in items:
                    items.append(node[0])
        return items

    def growtree(self):
        #create root node
        tree=fpnode(NoneNoneNoneself.addnode2itemtableisroot=True)
        for path in self.cpb:
            path_sorted=sorted(pathkey=lambda n:self.itemcount[n[0]]reverse=True)
            tree.grow(path_sorted)
        return tree

    def getitemcount(self):
        itemcount={}
        for path in self.cpb:
            for item in path:
                itemcount.setdefault(item[0]0)
                itemcount[item[0]]+=item[1]
        return itemcount


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-05-26 13:56  FP-tree\
     目录           0  2013-05-19 21:33  FP-tree\.idea\
     文件         171  2013-05-16 21:21  FP-tree\.idea\encodings.xml
     文件         355  2013-05-19 21:33  FP-tree\.idea\FP-tree.iml
     文件         219  2013-05-16 21:21  FP-tree\.idea\misc.xml
     文件         277  2013-05-16 21:21  FP-tree\.idea\modules.xml
     目录           0  2013-05-16 22:29  FP-tree\.idea\scopes\
     文件         143  2013-05-16 21:21  FP-tree\.idea\scopes\scope_settings.xml
     文件         173  2013-05-16 21:21  FP-tree\.idea\vcs.xml
     文件        4899  2013-05-16 21:21  FP-tree\.idea\workspace.xml
     文件        1084  2013-05-23 16:31  FP-tree\cpbtreebuilder.py
     文件        2590  2013-05-26 13:51  FP-tree\drawtree.py
     文件         528  2013-05-26 13:56  FP-tree\example.py
     文件        1696  2013-05-23 17:25  FP-tree\fpnode.py
     文件        5018  2013-05-26 13:43  FP-tree\fptreemining.py
     文件        1491  2013-05-26 13:40  FP-tree\node.py
     文件        2996  2013-05-23 15:34  FP-tree\sample.py
     文件        1455  2013-05-26 13:45  FP-tree\treebuilder.py
     文件        1478  2013-05-22 17:45  FP-tree\util.py
     目录           0  2013-05-26 13:52  FP-tree\__pycache__\
     文件        2038  2013-05-23 16:31  FP-tree\__pycache__\cpbtreebuilder.cpython-32.pyc
     文件        3860  2013-05-26 13:52  FP-tree\__pycache__\drawtree.cpython-32.pyc
     文件        2640  2013-05-24 10:11  FP-tree\__pycache__\fpnode.cpython-32.pyc
     文件        6619  2013-05-26 13:43  FP-tree\__pycache__\fptreemining.cpython-32.pyc
     文件        2979  2013-05-26 13:42  FP-tree\__pycache__\node.cpython-32.pyc
     文件        2092  2013-05-23 15:35  FP-tree\__pycache__\sample.cpython-32.pyc
     文件        2800  2013-05-26 13:52  FP-tree\__pycache__\treebuilder.cpython-32.pyc
     文件        2261  2013-05-22 17:45  FP-tree\__pycache__\util.cpython-32.pyc

评论

共有 条评论