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_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)
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()
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)