Pattern Recognition
Essay Preview: Pattern Recognition
Report this essay
load(usps_main,-mat);
%load maindata
%generate random number from 1 to 500
random= ceil(rand(1,100) * 500);
%make data of 200 samples
matrix= zeros(200,256);
for i=1:1:100
a=getonedigit(3,random(i),maindata);
c=getonedigit(8,random(i),maindata);
b=a(1:256);
d=c(1:256);
matrix(i,:)=b;
matrix(i+100,:)=d;
%make the labels matrix
labels= zeros(200,1);
labels(1:100)=3;
labels(101:200)=8;
count2=zeros(1,20);
x=zeros(1,256);
for k=1:1:20
for i=1:1:200
x=matrix(i,:);
y=knearest(k,x,matrix,labels);
if(y~=labels(i))
count2(1,k)=count2(1,k)+1;
plot(count2);
title(step 2)
%start of step 3
trainingset=zeros(100,256);
testingset=zeros(100,256);
labels3= zeros(100,1);
labels2=zeros(100,1);
labelIndex=1;
for i=1:1:100
trainingset(i,:)=matrix((i*2)-1,:);
labels3(i,1)=labels((i*2)-1);
testingset(i,:)=matrix((i*2),:);
labels2(i,1)=labels((i*2));
count3=zeros(1,20);
for k=1:1:20
for i=1:1:100
x=testingset(i,:);
y=knearest(k,x,trainingset,labels3);
if(y~=labels2(i))
count3(1,k)=count3(1,k)+1;
figure;
plot((100-count))
title(step 3)
%start of step 4
trainingset=zeros(100,256);
testingset=zeros(100,256);
labels3= zeros(100,1);
labels2=zeros(100,1);
labelIndex=1;
for i=1:1:100
trainingset(i,:)=matrix((i*2),:);
labels3(i,1)=labels((i*2));
testingset(i,:)=matrix((i*2)-1,:);
labels2(i,1)=labels((i*2)-1);
count4=zeros(1,20);
for k=1:1:20
for i=1:1:100
x=testingset(i,:);
y=knearest(k,x,trainingset,labels3);
if(y~=labels2(i))
count4(1,k)=count4(1,k)+1;
figure;
plot((100-count))
title(step 4)
%step 5
figure;
plot((100-count2)/100,red)
hold on;
plot((100-count3)/100,blue)
hold on;
plot((100-count4)/100,green)
title(step 2 result in red, 3 in blue, 4 in green)
ylabel(percentage of testing accuracy)
xlabel(value of k)

Get Your Essay

Cite this page

100-Count And Random Number. (July 4, 2021). Retrieved from https://www.freeessays.education/100-count-and-random-number-essay/