-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
50 lines (44 loc) · 1.47 KB
/
benchmark.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
import numpy as np
import time
import matplotlib.pyplot as plt
from core.csv_database import CsvDatabase
from core.factory import Factory
from core.apriori import Apriori
interval = 100
low_support = 0.1
high_support = 0.5
confidence = 0
def graph_runtime(runtimes):
plt.plot(np.linspace(low_support, high_support, interval), runtimes, label = 'runtime over support')
plt.xlabel('support')
plt.ylabel('runtime (in second)')
plt.legend()
plt.savefig('runtime.png')
plt.close()
def graph_numrules(numrules):
plt.plot(np.linspace(low_support, high_support, interval), numrules, label = 'runtime over support')
plt.xlabel('support')
plt.ylabel('number of rules')
plt.legend()
plt.savefig('numrules.png')
plt.close()
def main():
db = CsvDatabase('test_data/zero_one.csv')
Factory.setup_db(db)
runtimes = [] # store runtime (in second)
numrules = [] # store number of confident rules
for support in np.linspace(low_support, high_support, interval):
start_time = time.monotonic()
apriori = Apriori(db, support, confidence, None)
rules = apriori.generate_all_confidence_rules()
#for rule in rules:
# print(rule, ': ', rule.confidence)
end_time = time.monotonic()
runtimes.append(end_time - start_time)
numrule = len(rules)
numrules.append(numrule)
print('Support %.2f, runtime %.9f, numrules %d' % (support, end_time - start_time, numrule))
graph_runtime(runtimes)
graph_numrules(numrules)
if __name__ == '__main__':
main()