Matlab code for Classification of IRIS data using MLP (Multi Layer Perceptron)

I'm trying to execute the following matlab code but I'm getting error about Time steps (TS) which is presented in network/sim.m (predefined matlab code). I couldn't edit this sim.m.
close all; clear; clc
%%load divided input data set
load fisheriris
% coding (+1/-1) of 3 classes
a = [-1 -1 +1]';
b = [-1 +1 -1]';
c = [+1 -1 -1]';
% define training inputs
rand_ind = randperm(50);
trainSeto = meas(rand_ind(1:35),:);
trainSeto=trainSeto';
trainVers = meas(50 + rand_ind(1:35),:);
trainVers=trainVers';
trainVirg = meas(100 + rand_ind(1:35),:);
trainVirg=trainVirg';
trainInp = [trainSeto trainVers trainVirg];
% define targets
tmp1 = repmat(a,1,length(trainSeto));
tmp2 = repmat(b,1,length(trainVers));
tmp3 = repmat(c,1,length(trainVirg));
T = [tmp1 tmp2 tmp3];
%%network training
trainCor = zeros(10,10);
valCor = zeros(10,10);
Xn = zeros(1,10);
Yn = zeros(1,10) ;
for k = 1:10 ,
Yn(1,k) = k;
for n = 1:10,
Xn(1,n) = n;
net = newff(trainInp,T,[k n],{},'trainbfg');
net = init(net);
net.divideParam.trainRatio = 1;
net.divideParam.valRatio = 0;
net.divideParam.testRatio = 0;
net.trainParam.show = NaN;
net.trainParam.max_fail = 2;
rand_ind = randperm(50);
valSeto = meas(rand_ind(1:20),:);
valSeto= valSeto';
valVers = meas(50 + rand_ind(1:20),:);
valVers=valVers';
valVirg = meas(100 + rand_ind(1:20),:);
valVirg=valVirg';
valInp = [valSeto valVers valVirg];
VV.P = valInp;
tmp1 = repmat(a,1,length(valSeto));
tmp2 = repmat(b,1,length(valVers));
tmp3 = repmat(c,1,length(valVirg));
valT = [tmp1 tmp2 tmp3];
net = train(net,trainInp,T,[],[],VV);%,TV);
Y = sim(net,trainInp);
[Yval,Pfval,Afval,Eval,perfval] = sim(net,valInp,[],[],valT);
Error of my matlab code:

 Accepted Answer

At the moment it appears to me to be a bug in the sim code. It looks to me as if you could get around the bug by not requesting the 5th output of sim()

11 Comments

The Mathworks code looks to me to have problems, not something you can fix by reinstalling.
Change your line
[Yval,Pfval,Afval,Eval,perfval] = sim(net,valInp,[],[],valT);
To
[Yval,Pfval,Afval,Eval] = sim(net,valInp,[],[],valT);
Thank you sir, I got my required output. :)
Sir, I want to execute the output with each epoch (in figures). and I want to execute the orthogonal projections for training set and validation set. What commands i have to use to get these outputs?
Which MATLAB release are you using? newff() is obsolete now so I want to be sure that I look at documentation for your particular release.
newff() was replaced in R2010b. It was no longer documented after R2010a, so I cannot describe how it is intended to work in R2014a.
You should rewrite your code to use feedforwardnet() and another advances that came with R2010b.
What about orthogonal projection outputs? is it related with this newff()?
I would need to dig into the code to figure out if it is possible at all. I am reluctant to do that for code that was replaced over 6 years ago.
I got this code from here--> Classification of Iris data set but i made some modifications in loading the IRIS dataset.
I mean that I would need to dig into the Mathworks neural network code. I would rather not do that for the old code. You should re-write using feedforwardnet() instead of newff() and make other such appropriate changes.
Time spent investigating the inner working of code that was replaced six years ago would be a waste for me; I would have no further use for any information gained. Time spent investigating the current Mathworks code has the potential to be of use in future.
Okay I will rewrite this code. Thanks

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 23 Nov 2016

Commented:

on 2 Dec 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!