-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemporary.py
68 lines (51 loc) · 1.61 KB
/
temporary.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
65
66
67
68
import sys
import numpy as np
import pandas as pd
from apyori import apriori
inp = sys.argv[1];
split_inp = inp.split("//")
arr = []
for s in split_inp:
arr.append(s.split("||"))
# print(arr)
rules = apriori(transactions = arr, min_support = 0.03, min_confidence=0.05, min_lift = 1.25, min_length=2, max_length=2)
results = list(rules)
# print(results)
# for result in results:
# print(result)
# results = list[filter(lambda x: len(x.items) > 1, results)]
# print('helloooo '+str(list(rules)));
actual_results = []
for result in results:
if(len(result.items)==2):
actual_results.append(result)
# for result in actual_results:
# print(result)
# for actual_result in actual_results:
# print(str(actual_result.items)+" "+str(len(actual_result.items)))
lhs = [];
rhs = [];
supports = [];
confidences = [];
lifts = [];
for result in actual_results:
if len(tuple(result[2][1][1])) == 1 and len(tuple(result[2][1][0])) == 1:
lhs.append(tuple(result[2][1][0])[0])
rhs.append(tuple(result[2][1][1])[0])
supports.append(result[1])
confidences.append(result[2][1][2])
lifts.append(result[2][1][3])
if len(tuple(result[2][0][1])) == 1 and len(tuple(result[2][0][0])) == 1:
lhs.append(tuple(result[2][0][0])[0])
rhs.append(tuple(result[2][0][1])[0])
supports.append(result[1])
confidences.append(result[2][0][2])
lifts.append(result[2][0][3])
def foo(elem):
return elem[-1]
temp = list(zip(lhs,rhs,supports,confidences,lifts))
temp.sort(key=foo, reverse=True)
print(temp)
# for te in temp:
# print(te)
sys.stdout.flush()