-
Notifications
You must be signed in to change notification settings - Fork 0
/
knn_load_data.m
204 lines (198 loc) · 5.36 KB
/
knn_load_data.m
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
% MACHINE LEARNING PROJECT: KNN EMOTION CLASSIFICATION
clear all
clc
addpath(genpath(pwd));
disp(pwd)
CSV_PATH = 'Data_path.csv';
% loading csv with audio path of all files
csv_file = readtable(CSV_PATH);
%LENGTH FOR EACH CLASS*****************************************************
%disp('computing length for each class (in seconds)');
%{
for i = 0:5
class_len = 0;
for j = 1:height(csv_file)
if j == 18076
continue
end
if j == 5041
continue
end
line = csv_file(j, 1:4);
path = string(line.path);
label = string(line.labels);
% leaving out gender
%if string(line.gender) == 'male'
% continue
%end
switch i
case 0
if label == 'angry'
class_len = class_len + file_length(path);
end
case 1
if label == 'neutral'
class_len = class_len + file_length(path);
end
case 2
if label == 'sad'
class_len = class_len + file_length(path);
end
case 3
if label == 'happy'
class_len = class_len + file_length(path);
end
case 4
if label == 'fear'
class_len = class_len + file_length(path);
end
case 5
if label == 'disgust'
class_len = class_len + file_length(path);
end
end
end
switch i
case 0
disp(['angry' string(class_len)]);
case 1
disp(['neutral' string(class_len)]);
case 2
disp(['sad' string(class_len)]);
case 3
disp(['happy' string(class_len)]);
case 4
disp(['fear' string(class_len)]);
case 5
disp(['disgust' string(class_len)]);
end
end
%}
% x gender
%{
for i = 0:1
class_len = 0;
for j = 1:height(csv_file)
if j == 18076
continue
end
if j == 5041
continue
end
line = csv_file(j, 1:4);
path = string(line.path);
label = string(line.gender);
switch i
case 0
if label == 'female'
class_len = class_len + file_length(path);
end
case 1
if label == 'male'
class_len = class_len + file_length(path);
end
end
end
switch i
case 0
disp(['female' string(class_len)]);
case 1
disp(['male' string(class_len)]);
end
end
%}
% KNN CLASSIFICATION EMOTIONS**********************************************
disp('loading classes data');
for i = 0:5
list_class_path = [];
for j = 1:height(csv_file)
if j == 18076
continue
end
if j == 5041
continue
end
line = csv_file(j, 1:4);
% leaving out female
%if string(line.gender) == 'female'
% continue
%end
path = string(line.path);
label = string(line.labels);
switch i
case 0
if label == 'angry'
list_class_path = [list_class_path path];
end
case 1
if label == 'neutral'
list_class_path = [list_class_path path];
end
case 2
if label == 'sad'
list_class_path = [list_class_path path];
end
case 3
if label == 'happy'
list_class_path = [list_class_path path];
end
case 4
if label == 'fear'
list_class_path = [list_class_path path];
end
case 5
if label == 'disgust'
list_class_path = [list_class_path path];
end
end
end
label = '';
switch i
case 0
label = 'angry';
case 1
label = 'neutral';
case 2
label = 'sad';
case 3
label = 'happy';
case 4
label = 'fear';
case 5
label = 'disgust';
end
disp(['loading class:' string(i)]);
kNN_model_add_class('K_NN.mat', label, list_class_path, ...
{'mean', 'std'}, 0.200, 0.100, 3.0, 1.5);
end
%0.200, 0.100, 3.0, 1.5 -> 1 -> best
% KNN CLASSIFICATION GENDER************************************************
%{
list_class_path_male = [];
list_class_path_female = [];
for j = 1:height(csv_file)
if j == 18076
continue
end
if j == 5041
continue
end
line = csv_file(j, 1:4);
if string(line.labels) == 'surprise'
continue
end
path = string(line.path);
label = string(line.gender);
if label == 'male'
list_class_path_male = [list_class_path_male path];
end
if label == 'female'
list_class_path_female = [list_class_path_female path];
end
end
kNN_model_add_class('K_NN_gender.mat', 'male', list_class_path_male, ...
{'mean', 'std'}, 0.200, 0.100, 3.0, 1.5);
kNN_model_add_class('K_NN_gender.mat', 'female', list_class_path_female, ...
{'mean', 'std'}, 0.200, 0.100, 3.0, 1.5);
%}
disp('done.');