AllBestEssays.com - All Best Essays, Term Papers and Book Report
Search

Pattern Recognition

Essay by   •  April 5, 2012  •  Essay  •  677 Words (3 Pages)  •  1,449 Views

Essay Preview: Pattern Recognition

Report this essay
Page 1 of 3

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;

end

%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;

end

end

end

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));

end

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;

end

end

end

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);

end

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;

end

end

end

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')

...

...

Download as:   txt (4.8 Kb)   pdf (92.9 Kb)   docx (11.1 Kb)  
Continue for 2 more pages »
Only available on AllBestEssays.com