clc;clear all;close all;
%% STEP1 Load dataset
load DataSet
%% STEP2 Raw Data Visualization
plot(Data(:,1), Data(:,2), 's')
%% STEP3 Reference Data Preparation
ii=1; JJ=1;
for k=1:length(Data)
if Data(k,3) ==1
dog(i,:)=Data(k,:)
ii=ii+1;
else
cat(jj,:)=Data(k,:)
jj=jj+1;
%STEP 4 Visualization
plot(dog(:,1),dog(:,2),'r*')
hold on;
plot(cat(:,1), cat(:,2), 'o');
% Text Labeling
d1bar=sum(dog(:,1))/length(dog);
d2bar=sum(dog(:,2))/length(dog);
c1bar=sum(cat(:,1))/length(cat);
c2bar=sum(cat(:,2))/length(cat);
text(d1bar,d2bar,'Dog','FontSize',20)
text(c1bar,c2bar,'Cat','FontSize',20)
xlabel('X1','FontSize',20)
ylabel('X2','FontSize',20)
title('K-Nearest Neighbor','FontSize',15)
Y2xjO2NsZWFyIGFsbDtjbG9zZSBhbGw7CgolJSAgU1RFUDEgTG9hZCBkYXRhc2V0CmxvYWQgRGF0YVNldAoKJSUgU1RFUDIgUmF3IERhdGEgVmlzdWFsaXphdGlvbgoKcGxvdChEYXRhKDosMSksIERhdGEoOiwyKSwgJ3MnKQoKJSUgU1RFUDMgUmVmZXJlbmNlIERhdGEgUHJlcGFyYXRpb24KaWk9MTsgSko9MTsKZm9yIGs9MTpsZW5ndGgoRGF0YSkKICAgIGlmIERhdGEoaywzKSA9PTEKICAgICAgICBkb2coaSw6KT1EYXRhKGssOikKICAgICAgICBpaT1paSsxOwogICAgZWxzZQogICAgICAgIGNhdChqaiw6KT1EYXRhKGssOikKICAgICAgICBqaj1qaisxOwogICAgZW5kCmVuZAoKJVNURVAgNCBWaXN1YWxpemF0aW9uCglwbG90KGRvZyg6LDEpLGRvZyg6LDIpLCdyKicpCglob2xkIG9uOwoJcGxvdChjYXQoOiwxKSwgY2F0KDosMiksICdvJyk7CgoJJSBUZXh0IExhYmVsaW5nCglkMWJhcj1zdW0oZG9nKDosMSkpL2xlbmd0aChkb2cpOwoJZDJiYXI9c3VtKGRvZyg6LDIpKS9sZW5ndGgoZG9nKTsKCWMxYmFyPXN1bShjYXQoOiwxKSkvbGVuZ3RoKGNhdCk7CgljMmJhcj1zdW0oY2F0KDosMikpL2xlbmd0aChjYXQpOwoJdGV4dChkMWJhcixkMmJhciwnRG9nJywnRm9udFNpemUnLDIwKQoJdGV4dChjMWJhcixjMmJhciwnQ2F0JywnRm9udFNpemUnLDIwKQoJeGxhYmVsKCdYMScsJ0ZvbnRTaXplJywyMCkKCXlsYWJlbCgnWDInLCdGb250U2l6ZScsMjApCgl0aXRsZSgnSy1OZWFyZXN0IE5laWdoYm9yJywnRm9udFNpemUnLDE1KQ==
clc;clear all;close all;
%% STEP1 Load dataset
load DataSet
%% STEP2 Raw Data Visualization
plot(Data(:,1), Data(:,2), 's')
%% STEP3 Reference Data Preparation
ii=1; JJ=1;
for k=1:length(Data)
if Data(k,3) ==1
dog(i,:)=Data(k,:)
ii=ii+1;
else
cat(jj,:)=Data(k,:)
jj=jj+1;
end
end
%STEP 4 Visualization
plot(dog(:,1),dog(:,2),'r*')
hold on;
plot(cat(:,1), cat(:,2), 'o');
% Text Labeling
d1bar=sum(dog(:,1))/length(dog);
d2bar=sum(dog(:,2))/length(dog);
c1bar=sum(cat(:,1))/length(cat);
c2bar=sum(cat(:,2))/length(cat);
text(d1bar,d2bar,'Dog','FontSize',20)
text(c1bar,c2bar,'Cat','FontSize',20)
xlabel('X1','FontSize',20)
ylabel('X2','FontSize',20)
title('K-Nearest Neighbor','FontSize',15)