how can I do classification with Neural Network ?
Show older comments
i want to do data classification by using learning rule.i try to write some code but i must change my learning rate to get optimum solition.
if true
load fisheriris
traindata=[meas(1:25,:);meas(51:75,:);meas(101:125,:)];
testdata=[meas(26:50,:);meas(76:100,:);meas(126:150,:)];
traindata_class=[zeros(25,1);ones(25,1);-ones(25,1)];
testdata_class=[zeros(25,1);ones(25,1);-ones(25,1)];
traindata=traindata';
testdata=testdata';
traindata_class=traindata_class';
testdata_class=testdata_class';
net=newff(traindata,traindata_class,[5],{'tansig'},'traingdx');
net.trainParam.epochs=100;
net.trainParam.max_fail=20;
[net,tr]=train(net,traindata,traindata_class); cikis_ysa=sim(net,testdata); cikis_ysa=round(cikis_ysa);
hata=0;
for i=1:75
if (cikis_ysa(i)-testdata_class(i)~=0)
hata=hata+1;
end
end
yuzdehata=100*hata/75;
dogruluk=100-yuzdehata;
end
Accepted Answer
More Answers (1)
Greg Heath
on 21 Dec 2012
Edited: Greg Heath
on 21 Dec 2012
close all, clear all, clc
tic
[ x , t ] = iris_dataset;
whos
[ I N ] = size(x) % [ 4 150 ]
[ O N ] = size(t) % [ 3 150 ]
itrn = [ (1:25), (51:75), (101:125) ];
itst = [ (26:50), (76:100), (126:150) ];
xtrn = x( : , itrn); xtst = x( : , itst);
ttrn = t( : , itrn); ttst =t( : , itst);
trnclass0 = vec2ind(ttrn)
tstclass0 = vec2ind(ttst)
H = 5
Ntrials = 10
rng(0)
for i = 1:Ntrials
net = newpr(xtrn,ttrn,H); % See help newpr
net.divideFcn = ''; % Override default 0.7/0.15/0.15
[net tr Ytrn Etrn ] = train(net,xtrn,ttrn);
Nepochs(i,1) = tr.epoch(end);
trnclass = vec2ind(Ytrn);
Nerrtrn(i,1) = sum(trnclass ~= trnclass0);
Ytst = sim(net,xtst);
tstclass = vec2ind(Ytst);
Nerrtst(i,1) = sum(tstclass ~= tstclass0);
end
disp( 'Nepochs Nerrtrn Nerrtst ');
disp( [ Nepochs, Nerrtrn, Nerrtst ] );
time = toc
Thank you for formally accepting my answer.
Greg
1 Comment
mittal54
on 11 May 2015
that was helpful... thanks
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!