-
Notifications
You must be signed in to change notification settings - Fork 75
/
test_emotion.py
44 lines (35 loc) · 1.4 KB
/
test_emotion.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
# encoding=utf8
import os
import numpy as np
import FukuML.Utility as utility
import FukuML.SupportVectorMachine as svm
input_train_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), 'FukuML/dataset/emotion.dat')
cross_validator = utility.CrossValidator()
svm_mc = svm.MultiClassifier()
svm_mc.load_train_data(input_train_data_file)
svm_mc.set_param(svm_kernel='soft_gaussian_kernel', gamma=1, C=5)
cross_validator.add_model(svm_mc)
avg_errors = cross_validator.excute()
print(avg_errors)
svm_mc = svm.MultiClassifier()
svm_mc.load_train_data(input_train_data_file)
svm_mc.set_param(svm_kernel='soft_gaussian_kernel', gamma=1, C=5)
svm_mc.init_W()
svm_mc.train()
'''
for class_item in svm_mc.class_list:
print(class_item)
print(svm_mc.classifier_list[class_item].alpha)
error_sv = (svm_mc.classifier_list[class_item].alpha > 0.999999999)
print(np.arange(len(svm_mc.classifier_list[class_item].alpha))[error_sv])
'''
print("W 平均錯誤值(Ein):")
print(svm_mc.calculate_avg_error_all_class(svm_mc.train_X, svm_mc.train_Y, svm_mc.W))
data_num = len(svm_mc.train_Y)
for i in range(data_num):
x_string = np.array(map(str, svm_mc.train_X[i]))
x_string = ' '.join(x_string[1:])+' '+str(svm_mc.train_Y[i])
prediction = svm_mc.prediction(x_string)
if (float(prediction['prediction']) != float(prediction['input_data_y'])):
print(i+1)
print(prediction)