-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathsvmClassifier.py
112 lines (87 loc) · 3.61 KB
/
svmClassifier.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
import numpy
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
def svm_classifier():
file_x = 'data/features_sampled.dat'
file_y = 'data/label_class_0.dat'
X = numpy.genfromtxt(file_x, delimiter=' ')
y = numpy.genfromtxt(file_y, delimiter=' ')
# Split the data into training/testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# SVM Classifier
clf = SVC(kernel = 'rbf', random_state = 42)
clf.fit(X_train, y_train)
y_predict = clf.predict(X_test)
cm = confusion_matrix(y_test, y_predict)
print(cm)
print("Accuracy score of Valence ")
print(accuracy_score(y_test, y_predict)*100)
###############################################################
file_x = 'data/features_sampled.dat'
file_y = 'data/label_class_1.dat'
X = numpy.genfromtxt(file_x, delimiter=' ')
y = numpy.genfromtxt(file_y, delimiter=' ')
# Split the data into training/testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# SVM Classifier
clf = SVC(kernel = 'rbf', random_state = 42)
clf.fit(X_train, y_train)
y_predict = clf.predict(X_test)
cm = confusion_matrix(y_test, y_predict)
print(cm)
print("Accuracy score of Arousal ")
print(accuracy_score(y_test, y_predict)*100)
####################################################################
file_x = 'data/features_sampled.dat'
file_y = 'data/label_class_2.dat'
X = numpy.genfromtxt(file_x, delimiter=' ')
y = numpy.genfromtxt(file_y, delimiter=' ')
# Split the data into training/testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# SVM Classifier
clf = SVC(kernel = 'rbf', random_state = 42)
clf.fit(X_train, y_train)
y_predict = clf.predict(X_test)
cm = confusion_matrix(y_test, y_predict)
print(cm)
print("Accuracy score of Dominance ")
print(accuracy_score(y_test, y_predict)*100)
######################################################################3
file_x = 'data/features_sampled.dat'
file_y = 'data/label_class_3.dat'
X = numpy.genfromtxt(file_x, delimiter=' ')
y = numpy.genfromtxt(file_y, delimiter=' ')
# Split the data into training/testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# SVM Classifier
clf = SVC(kernel = 'rbf', random_state = 42)
clf.fit(X_train, y_train)
y_predict = clf.predict(X_test)
cm = confusion_matrix(y_test, y_predict)
print(cm)
print("Accuracy score of liking ")
print(accuracy_score(y_test, y_predict)*100)
if __name__ == '__main__':
svm_classifier()