MATLAB Answers

0

Input and target have different number of sampel

Asked by Oman Wisni on 14 Nov 2018
Latest activity Commented on by Oman Wisni on 21 Mar 2019
Hi, I have some code her and following some example how to create neural network using toolbox. I have matrix with dimension like below
load datatrain1.mat
input = cell2mat(Train); %220x25 dimension
load classtrain1.mat
target = cell2mat(TTrain); %220x1 dimension
net = newff(input,target,[100 11],{'logsig','logsig'},'trainlm');
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-6;
net = train(net,input,target);
output = round(sim(net,input));
But when I run this code I get Error. In this code
net = train(net,input,target);
The error like this Inputs and targets have different numbers of samples.
How I fix it? is there any way for fix it?
Any help will be must appreciated. Thanks

  0 Comments

Sign in to comment.

2 Answers

Answer by Greg Heath
on 21 Mar 2019
 Accepted Answer

Train and TTrain have to be transposed.
Hope this helps.
THANK YOU FOR FORMALLY ACCEPTING MY ANSWER
Greg

  1 Comment

Thank you for the answer Mr.Greg

Sign in to comment.


Answer by Osama Tabbakh on 20 Mar 2019

You have to let the whole data in cell, so that Matlab know which input belong to which target.
p %% input
p = con2seq (p);
t %% target
t = con2seq (t);
net = newff(p,t,[2 2]);
net.divideParam.trainRatio=0.7;
net.divideParam.testRatio=0.15;
net.divideParam.valRatio=0.15;
net.trainParam.lr=0.01;
net.trainParam.min_grad=1e-20;
net.trainParam.goal=1e-30;
net.trainParam.epochs=200;
net = train(net,p,t);
But when you do this there will be no test and validation. I don't know why.

  1 Comment

Thank you for the answer sir,

Sign in to comment.