I have some trouble on predicting KNN classifier without using built-in function. I got stuck here and had no idea how to go to next step. Here is my code:
% calculate Euclidean distance
dist = pdist2(test, train, 'euclidean');
for k = [1 3 5 7]
[~, nearest] = sort(dist, 2);
nearst = nearest(:, 1:k);
end % for loop
Where test
is a 297x64 matrix, and train
is a 1500x64 matrix. The dist
matrix is 297x1500. Any help will be thankful!