-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknn.m
27 lines (22 loc) · 1012 Bytes
/
knn.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
function mdl = knn()
%Machine Learning
gtrue = []; %Initilize GT matrix of all samples
features = []; %Initilize features matrix for all samples
for subject = 0:20 %Iterate through each patient
[EEG,seizureGT] = loadfile(subject); %Load the specific patient
for channel = 1:23 %Iterate through each channel
band = 5; %All 0.5- 30Hz range
window = 500; %Fast Processing (Could change later) (took ~20 min)
%Extract 3 features (RMS, MedFreq,Entropy)
[ftemp] = eegmeasure(EEG(channel).ch,band,window);
%Extract the segmented GT of specific subject
[gtemp] = truthsegment(seizureGT,window);
%Add the specific subject features to the GLOBAL feature matrix
features = [features;ftemp];
%Add the specific subject GT to the GLOBAL GT matrix
gtrue = [gtrue;gtemp];
end
end
%Finally Train the KNN model with the created GLOBAL feature & GT marixs
mdl = fitcknn(features,gtrue,'NumNeighbors',5,'Standardize',1);
end