-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest.py
More file actions
35 lines (27 loc) · 1.17 KB
/
Copy pathtest.py
File metadata and controls
35 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# python3
# -*- coding: utf-8 -*-
# @Author : lina
# @Time : 2018/5/13 11:40
import fp_growth_py3 as fpg
# 数据集
dataset = [
['啤酒', '牛奶', '可乐'],
['尿不湿', '啤酒', '牛奶', '橙汁'],
['啤酒', '尿不湿'],
['啤酒', '可乐', '尿不湿'],
['啤酒', '牛奶', '可乐']
]
if __name__ == '__main__':
'''
调用find_frequent_itemsets()生成频繁项
@:param minimum_support表示设置的最小支持度,即若支持度大于等于inimum_support,保存此频繁项,否则删除
@:param include_support表示返回结果是否包含支持度,若include_support=True,返回结果中包含itemset和support,否则只返回itemset
'''
frequent_itemsets = fpg.find_frequent_itemsets(dataset, minimum_support=1, include_support=True)
print(type(frequent_itemsets)) # print type
result = []
for itemset, support in frequent_itemsets: # 将generator结果存入list
result.append((itemset, support))
result = sorted(result, key=lambda i: i[0]) # 排序后输出
for itemset, support in result:
print(str(itemset) + ' ' + str(support))