-
Notifications
You must be signed in to change notification settings - Fork 1
/
A1_kycheungav_20424915_code_close.py
64 lines (51 loc) · 1.92 KB
/
A1_kycheungav_20424915_code_close.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import A1_kycheungav_20424915_code_relim as relim
import numpy as np
import timeit
class closed:
def __init__(self):
self.Freq = self.getFreq()
self.Closed = None
self.Max = None
def getData(self):
results = []
with open('freq_items_datasets.txt','r') as inputfile:
for line in inputfile:
results.append(line.strip().split(' '))
results_np = np.array([np.array(lines) for lines in results])
return results_np
def getFreq(self):
item_mining = relim.freq_mining(self.getData(), 150, 0.5)
return item_mining.freq_items()
def filtering(self):
self.Closed = self.Freq.copy()
self.Max = self.Closed.copy()
i = self.Freq
j = self.Freq
for set1, count1 in list(i.items()):
for set2, count2 in list(j.items()):
if set1 < set2:
self.Max.pop(set1, None)
if count1 <= count2:
self.Closed.pop(set1, None)
#must run the closedPattern before running this function
def maxPattern(self):
self.Max = self.Closed.copy()
i = self.Closed
j = self.Closed
for set1, count1 in list(i.items()):
for set2, count2 in list(j.items()):
if set1 < set2:
self.Max.pop(set1, None)
print(self.Max)
if __name__ == "__main__":
t_start = timeit.default_timer()
pattern = closed()
print("number of total frequent item set", len(pattern.Freq))
pattern.filtering()
print(pattern.Closed)
print("number of closed frequent item set", len(pattern.Closed))
print(pattern.Max)
print("number of maximal frequent item set", len(pattern.Max))
t_end = timeit.default_timer()
cost = t_end -t_start
print ( 'Time cost of funl is %f' %cost)