-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
33 lines (24 loc) · 717 Bytes
/
utils.py
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
import time
from pymining import itemmining
def timing(f):
"""
Decorator to compute the performance of a function
:param f: function
:return: wrapped function
"""
def wrap(*args):
time1 = time.time()
ret = f(*args)
time2 = time.time()
print('{:s} function took {:.3f} ms'.format(f.__name__, (time2-time1)*1000.0))
return (time2-time1)*1000.0, ret
return wrap
def count_occurences(res, length):
count = [0 for x in range(0, length)]
for e in res:
if not len(e) > length:
count[len(e)-1] += 1
return count
@timing
def frequent_itemset(input, min_supp):
return itemmining.relim(input, min_support=min_supp)