This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
120 lines (104 loc) · 4.28 KB
/
tests.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import numpy as np
import unittest
from business_rules import run_all
from test_cases import song_list
from rules import rules_json
from models import SongVariables, SongActions
class SongTests(unittest.TestCase):
def setUp(self):
self.rules = rules_json
def test_case_0(self):
song = song_list[0]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
def test_case_1(self):
song = song_list[1]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
def test_case_3(self):
song = song_list[3]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
def test_case_4(self):
song = song_list[4]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
def test_case_5(self):
song = song_list[5]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
def test_case_6_to_25(self):
for i in range(6, 26):
song = song_list[i]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
def test_case_26_to_50(self):
for i in range(26, 50):
song = song_list[i]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
from pandas import DataFrame
from pandas_ml import ConfusionMatrix
import seaborn as sns
import matplotlib.pyplot as plt
class ModelAccuracyTest(unittest.TestCase):
def setUp(self):
self.rules = rules_json
def test_accuracy(self):
total = 50
correct = 0
df = DataFrame(index=range(0,50), columns=['true', 'predict'])
for i in range(0,50):
song = song_list[i]['song']
true_genre = song.genre
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
df.loc[i] = [true_genre, song.genre]
if true_genre == song.genre:
correct += 1
print(correct/total)
cnf_matrix = ConfusionMatrix(df['true'], df['predict'])
cnf_matrix.plot()
plt.show()
self.assertGreater((correct/total), 0.5)
def confusion_matrix(self):
df = DataFrame(index=range(0,50), columns=['true', 'predict'])
for i in range(0, 50):
song = song_list[i]['song']
true_genre = str(song.genre)
run_all(rule_list=self.rules,
defined_variables=SongVariables(song),
defined_actions=SongActions(song),
stop_on_first_trigger=False)
df.loc[i] = [true_genre, song.genre]
cnf_matrix = ConfusionMatrix(df['true'], df['predict'])
cnf_matrix.plot()
plt.show()
if __name__ == '__main__':
accuracy_tests = unittest.TestLoader().loadTestsFromTestCase(ModelAccuracyTest)
unittest.TextTestRunner(verbosity=1).run(accuracy_tests)
song_tests = unittest.TestLoader().loadTestsFromTestCase(SongTests)
unittest.TextTestRunner(verbosity=1).run(song_tests)