源代码:仓库地址
数据挖掘常用算法对比测试
Usage
git clone git@github.com:JackHCC/Apriori-and-FP_Growth.git
cd Apriori-and-FP_Growth
- Apriori
python Apriori.py
- FP-Growth
python FP_Growth.py
DataSet设置
data_set = [
[‘牛奶’, ‘鸡蛋’, ‘面包’, ‘薯片’],
[‘鸡蛋’, ‘爆米花’, ‘薯片’, ‘啤酒’],
[‘牛奶’, ‘啤酒’, ‘面包’],
[‘牛奶’, ‘鸡蛋’, ‘面包’, ‘爆米花’, ‘啤酒’, ‘薯片’],
[‘鸡蛋’, ‘面包’, ‘薯片’],
[‘鸡蛋’, ‘面包’, ‘啤酒’, ],
[‘牛奶’, ‘面包’, ‘薯片’],
[‘牛奶’, ‘鸡蛋’, ‘面包’, ‘黄油’, ‘薯片’],
[‘牛奶’, ‘鸡蛋’, ‘黄油’, ‘薯片’]
]
Apriori算法
运行结果:
==================================================
frequent 1-itemsets(频繁项集) support(支持度)
==================================================
frozenset({'啤酒'}) 0.4444444444444444
frozenset({'面包'}) 0.7777777777777778
frozenset({'薯片'}) 0.7777777777777778
frozenset({'爆米花'}) 0.2222222222222222
frozenset({'鸡蛋'}) 0.7777777777777778
frozenset({'黄油'}) 0.2222222222222222
frozenset({'牛奶'}) 0.6666666666666666
==================================================
frequent 2-itemsets(频繁项集) support(支持度)
==================================================
frozenset({'鸡蛋', '黄油'}) 0.2222222222222222
frozenset({'牛奶', '鸡蛋'}) 0.4444444444444444
frozenset({'牛奶', '黄油'}) 0.2222222222222222
frozenset({'薯片', '面包'}) 0.5555555555555556
frozenset({'牛奶', '啤酒'}) 0.2222222222222222
frozenset({'爆米花', '啤酒'}) 0.2222222222222222
frozenset({'牛奶', '面包'}) 0.5555555555555556
frozenset({'薯片', '牛奶'}) 0.5555555555555556
frozenset({'鸡蛋', '啤酒'}) 0.3333333333333333
frozenset({'面包', '鸡蛋'}) 0.5555555555555556
frozenset({'薯片', '鸡蛋'}) 0.6666666666666666
frozenset({'薯片', '啤酒'}) 0.2222222222222222
frozenset({'面包', '啤酒'}) 0.3333333333333333
frozenset({'薯片', '黄油'}) 0.2222222222222222
frozenset({'爆米花', '鸡蛋'}) 0.2222222222222222
frozenset({'薯片', '爆米花'}) 0.2222222222222222
==================================================
frequent 3-itemsets(频繁项集) support(支持度)
==================================================
frozenset({'薯片', '牛奶', '黄油'}) 0.2222222222222222
frozenset({'牛奶', '面包', '鸡蛋'}) 0.3333333333333333
frozenset({'牛奶', '面包', '啤酒'}) 0.2222222222222222
frozenset({'薯片', '爆米花', '啤酒'}) 0.2222222222222222
frozenset({'爆米花', '鸡蛋', '啤酒'}) 0.2222222222222222
frozenset({'薯片', '爆米花', '鸡蛋'}) 0.2222222222222222
frozenset({'薯片', '面包', '鸡蛋'}) 0.4444444444444444
frozenset({'牛奶', '鸡蛋', '黄油'}) 0.2222222222222222
frozenset({'面包', '鸡蛋', '啤酒'}) 0.2222222222222222
frozenset({'薯片', '鸡蛋', '啤酒'}) 0.2222222222222222
frozenset({'薯片', '鸡蛋', '黄油'}) 0.2222222222222222
frozenset({'薯片', '牛奶', '面包'}) 0.4444444444444444
frozenset({'薯片', '牛奶', '鸡蛋'}) 0.4444444444444444
强关联
frozenset({'黄油'}) => frozenset({'鸡蛋'}) conf(置信度): 1.0
frozenset({'黄油'}) => frozenset({'牛奶'}) conf(置信度): 1.0
frozenset({'薯片'}) => frozenset({'面包'}) conf(置信度): 0.7142857142857143
frozenset({'面包'}) => frozenset({'薯片'}) conf(置信度): 0.7142857142857143
frozenset({'爆米花'}) => frozenset({'啤酒'}) conf(置信度): 1.0
frozenset({'牛奶'}) => frozenset({'面包'}) conf(置信度): 0.8333333333333334
frozenset({'面包'}) => frozenset({'牛奶'}) conf(置信度): 0.7142857142857143
frozenset({'牛奶'}) => frozenset({'薯片'}) conf(置信度): 0.8333333333333334
frozenset({'薯片'}) => frozenset({'牛奶'}) conf(置信度): 0.7142857142857143
frozenset({'啤酒'}) => frozenset({'鸡蛋'}) conf(置信度): 0.75
frozenset({'鸡蛋'}) => frozenset({'面包'}) conf(置信度): 0.7142857142857143
frozenset({'面包'}) => frozenset({'鸡蛋'}) conf(置信度): 0.7142857142857143
frozenset({'鸡蛋'}) => frozenset({'薯片'}) conf(置信度): 0.8571428571428571
frozenset({'薯片'}) => frozenset({'鸡蛋'}) conf(置信度): 0.8571428571428571
frozenset({'啤酒'}) => frozenset({'面包'}) conf(置信度): 0.75
frozenset({'黄油'}) => frozenset({'薯片'}) conf(置信度): 1.0
frozenset({'爆米花'}) => frozenset({'鸡蛋'}) conf(置信度): 1.0
frozenset({'爆米花'}) => frozenset({'薯片'}) conf(置信度): 1.0
frozenset({'牛奶', '黄油'}) => frozenset({'薯片'}) conf(置信度): 1.0
frozenset({'薯片', '黄油'}) => frozenset({'牛奶'}) conf(置信度): 1.0
frozenset({'黄油'}) => frozenset({'薯片', '牛奶'}) conf(置信度): 1.0
frozenset({'牛奶', '鸡蛋'}) => frozenset({'面包'}) conf(置信度): 0.75
frozenset({'牛奶', '啤酒'}) => frozenset({'面包'}) conf(置信度): 1.0
frozenset({'薯片', '爆米花'}) => frozenset({'啤酒'}) conf(置信度): 1.0
frozenset({'爆米花', '啤酒'}) => frozenset({'薯片'}) conf(置信度): 1.0
frozenset({'薯片', '啤酒'}) => frozenset({'爆米花'}) conf(置信度): 1.0
frozenset({'爆米花'}) => frozenset({'薯片', '啤酒'}) conf(置信度): 1.0
frozenset({'爆米花', '鸡蛋'}) => frozenset({'啤酒'}) conf(置信度): 1.0
frozenset({'爆米花', '啤酒'}) => frozenset({'鸡蛋'}) conf(置信度): 1.0
frozenset({'爆米花'}) => frozenset({'鸡蛋', '啤酒'}) conf(置信度): 1.0
frozenset({'爆米花', '鸡蛋'}) => frozenset({'薯片'}) conf(置信度): 1.0
frozenset({'薯片', '爆米花'}) => frozenset({'鸡蛋'}) conf(置信度): 1.0
frozenset({'爆米花'}) => frozenset({'薯片', '鸡蛋'}) conf(置信度): 1.0
frozenset({'面包', '鸡蛋'}) => frozenset({'薯片'}) conf(置信度): 0.7999999999999999
frozenset({'薯片', '面包'}) => frozenset({'鸡蛋'}) conf(置信度): 0.7999999999999999
frozenset({'牛奶', '黄油'}) => frozenset({'鸡蛋'}) conf(置信度): 1.0
frozenset({'鸡蛋', '黄油'}) => frozenset({'牛奶'}) conf(置信度): 1.0
frozenset({'黄油'}) => frozenset({'牛奶', '鸡蛋'}) conf(置信度): 1.0
frozenset({'薯片', '啤酒'}) => frozenset({'鸡蛋'}) conf(置信度): 1.0
frozenset({'鸡蛋', '黄油'}) => frozenset({'薯片'}) conf(置信度): 1.0
frozenset({'薯片', '黄油'}) => frozenset({'鸡蛋'}) conf(置信度): 1.0
frozenset({'黄油'}) => frozenset({'薯片', '鸡蛋'}) conf(置信度): 1.0
frozenset({'薯片', '牛奶'}) => frozenset({'面包'}) conf(置信度): 0.7999999999999999
frozenset({'牛奶', '面包'}) => frozenset({'薯片'}) conf(置信度): 0.7999999999999999
frozenset({'薯片', '面包'}) => frozenset({'牛奶'}) conf(置信度): 0.7999999999999999
frozenset({'牛奶', '鸡蛋'}) => frozenset({'薯片'}) conf(置信度): 1.0
frozenset({'薯片', '牛奶'}) => frozenset({'鸡蛋'}) conf(置信度): 0.7999999999999999
运行时间: 0.005999088287353516
FP-Growth算法
运行结果:
['啤酒'] 4
['啤酒', '爆米花'] 2
['爆米花'] 2
['牛奶'] 6
['牛奶', '啤酒'] 2
['牛奶', '啤酒', '爆米花'] 1
['牛奶', '爆米花'] 1
['牛奶', '黄油'] 2
['薯片'] 7
['薯片', '啤酒'] 2
['薯片', '啤酒', '爆米花'] 2
['薯片', '爆米花'] 2
['薯片', '牛奶'] 5
['薯片', '牛奶', '啤酒'] 1
['薯片', '牛奶', '啤酒', '爆米花'] 1
['薯片', '牛奶', '爆米花'] 1
['薯片', '牛奶', '黄油'] 2
['薯片', '黄油'] 2
['面包'] 7
['面包', '啤酒'] 3
['面包', '啤酒', '爆米花'] 1
['面包', '爆米花'] 1
['面包', '牛奶'] 5
['面包', '牛奶', '啤酒'] 2
['面包', '牛奶', '啤酒', '爆米花'] 1
['面包', '牛奶', '爆米花'] 1
['面包', '牛奶', '黄油'] 1
['面包', '薯片'] 5
['面包', '薯片', '啤酒'] 1
['面包', '薯片', '啤酒', '爆米花'] 1
['面包', '薯片', '爆米花'] 1
['面包', '薯片', '牛奶'] 4
['面包', '薯片', '牛奶', '啤酒'] 1
['面包', '薯片', '牛奶', '啤酒', '爆米花'] 1
['面包', '薯片', '牛奶', '爆米花'] 1
['面包', '薯片', '牛奶', '黄油'] 1
['面包', '薯片', '黄油'] 1
['面包', '黄油'] 1
['鸡蛋'] 7
['鸡蛋', '啤酒'] 3
['鸡蛋', '啤酒', '爆米花'] 2
['鸡蛋', '爆米花'] 2
['鸡蛋', '牛奶'] 4
['鸡蛋', '牛奶', '啤酒'] 1
['鸡蛋', '牛奶', '啤酒', '爆米花'] 1
['鸡蛋', '牛奶', '爆米花'] 1
['鸡蛋', '牛奶', '黄油'] 2
['鸡蛋', '薯片'] 6
['鸡蛋', '薯片', '啤酒'] 2
['鸡蛋', '薯片', '啤酒', '爆米花'] 2
['鸡蛋', '薯片', '爆米花'] 2
['鸡蛋', '薯片', '牛奶'] 4
['鸡蛋', '薯片', '牛奶', '啤酒'] 1
['鸡蛋', '薯片', '牛奶', '啤酒', '爆米花'] 1
['鸡蛋', '薯片', '牛奶', '爆米花'] 1
['鸡蛋', '薯片', '牛奶', '黄油'] 2
['鸡蛋', '薯片', '黄油'] 2
['鸡蛋', '面包'] 5
['鸡蛋', '面包', '啤酒'] 2
['鸡蛋', '面包', '啤酒', '爆米花'] 1
['鸡蛋', '面包', '爆米花'] 1
['鸡蛋', '面包', '牛奶'] 3
['鸡蛋', '面包', '牛奶', '啤酒'] 1
['鸡蛋', '面包', '牛奶', '啤酒', '爆米花'] 1
['鸡蛋', '面包', '牛奶', '爆米花'] 1
['鸡蛋', '面包', '牛奶', '黄油'] 1
['鸡蛋', '面包', '薯片'] 4
['鸡蛋', '面包', '薯片', '啤酒'] 1
['鸡蛋', '面包', '薯片', '啤酒', '爆米花'] 1
['鸡蛋', '面包', '薯片', '爆米花'] 1
['鸡蛋', '面包', '薯片', '牛奶'] 3
['鸡蛋', '面包', '薯片', '牛奶', '啤酒'] 1
['鸡蛋', '面包', '薯片', '牛奶', '啤酒', '爆米花'] 1
['鸡蛋', '面包', '薯片', '牛奶', '爆米花'] 1
['鸡蛋', '面包', '薯片', '牛奶', '黄油'] 1
['鸡蛋', '面包', '薯片', '黄油'] 1
['鸡蛋', '面包', '黄油'] 1
['鸡蛋', '黄油'] 2
['黄油'] 2
运行时间: 0.0019910335540771484
对比
FP-Growth算法的效率更高