-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathknn_svc.m
35 lines (32 loc) · 992 Bytes
/
knn_svc.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
%==========================================================================
% Create KNN plotting
%==========================================================================
% Example
%
% [result]=knn_svc(k,Samples) % Samples: dim x N
%
%==========================================================================
% January 13, 2009
% Implemented by Daewon Lee
% WWW: http://sites.google.com/site/daewonlee/
%==========================================================================
function [result]=knn_svc(k,Samples)
N=size(Samples,2);
result=zeros(N,k);
for i=1:N
temp=dist2(Samples(:,i)',Samples');
[dummy ind]=sort(temp);
result(i,:)=ind(1,2:k+1);
end
if size(Samples,1)==2
figure;
hold on
for i=1:N
for j=1:k
temp=[Samples(:,i)';Samples(:,result(i,j))'];
plot(temp(:,1),temp(:,2));
end
end
title('Proximity graph by K-Nearest neighborhood (KNN)');
hold off
end