-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmotion-Recognition-RandomSeed.py
53 lines (43 loc) · 1.57 KB
/
Emotion-Recognition-RandomSeed.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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from pandas.tools.plotting import scatter_matrix
data = pd.read_csv('../Emotion_features.csv')
feature = data.ix[:, 'tempo':]
labels = list(feature)
color = ['red' if l==1 else 'green' if l==2 else 'blue' if l==3 else 'orange' for l in data['label']]
plt.style.use('ggplot')
array = np.array(data)
array2 = np.array(data2)
result = []
xlabel = []
color = []
colors = ['red', 'green', 'blue']
index = 0
for random_seed in range(1, 11):
features = array[:, 5:]
tests= array2[:, 3:]
test_size = 0.09
labels = data.ix[:, 'class'].dropna()
train_d, test_d, train_l, test_l = train_test_split(features, labels, test_size=test_size, random_state=random_seed)
for neighbors in range(1, 11):
kNN = KNeighborsClassifier(n_neighbors=neighbors)
kNN.fit(train_d, train_l)
#prediction = kNN.predict(test_d)
prediction2=kNN.predict(tests)
xlabel.append(neighbors)
result.append(accuracy_score(prediction2,test_l))
color.append(colors[index])
index = (index+1)%3
plt.figure(figsize=(10, 10))
plt.xlabel('kNN Neighbors for k=1,2...10')
plt.ylabel('Accuracy Score')
plt.title('kNN Classifier Results')
plt.ylim(0, 1)
plt.scatter(xlabel, result, color=color)
plt.savefig('10-folds kNN Result.png')
plt.show()