Neural nw : Inputs and targets have different numbers of samples
Show older comments
Hi All
I have a code , I am just checking how it works , my input matrice is :
input = [0.0600000000000000 0.00100000000000000 45 0.0508000000000000 0.0127000000000000]
and the target is a 6 by 6 matrix
so using this code bellow , I get the mentioned error : Inputs and targets have different numbers of samples ,
Error in Neural (line 17) , [net,tr] = train(net,xn_tr,yn_tr);
here is the full code :
clc
clear
clear all
load('input.txt')
%load input
load ('taget.txt')
%normalizing data
[xn_tr,xs_tr] = mapstd(input);
[yn_tr,ys_tr] = mapstd(taget);
%%network
net=newff(xn_tr,yn_tr,[7 7],{'tansig'},'traingda');%7 hidden tanh layer gradian descent adaptive
net.trainParam.epochs =70;
net.trainParam.lr = 0.05;
net.trainParam.lr_inc = 1.05;
%training network
net.trainFcn='traingda';
[net,tr] = train(net,xn_tr,yn_tr);
%randomizing initial value f weight matrix
net = init(net);
net.trainParam.show = NaN;
u_t=mapstd('apply',x,xs_tr);
%simulating output
y_hat=sim(net,u_t);
%plotting performance
plotperform(tr)
mse=mse(y-y_hat)
4 Comments
farzad
on 12 Feb 2015
Greg Heath
on 13 Feb 2015
It looks like you are trying to make a mountain out of a molehill.
1. [ 7 7 ] in newff specifies 2 hidden layers. One is sufficient
2. Where in the world did you get the number 7 from?
3. Why use the obsolete newff instead of the current patternnet?
4. If you don't have patternnet, why use newff instead of newpr for pattern-recognition?
5. Why are you specifying parameter values that are already have defaults?
6. If this is for practice, why aren't you using the MATLAB practice datasets?
help nndatasets
doc nndatasets?
7. There are hundreds of successful classification posts in the NEWSGROUP and ANSWERS. Why not use one of those?
farzad
on 14 Feb 2015
Greg Heath
on 14 Feb 2015
Dear and respected Dr. Greg
% I really appreciate your very kind attention , honestly I have a really short time , too short to learn this coding step by step ,the next topic will be optimization for me to learn , I wish I could do it fast , I am reading the MATLAB help,pdf on Neural NW, well in the nndatasets ,I get a bit lost, where to start ,and after all , seeing a lot of different ways that might not be similar to these code , I should come back to this code to see what is wrong in it
I do not recommend using this code. Start out with the code in
help newpr
and
doc newpr
Then search the NEWSGROUP and ANSWERS using the search word newpr
NEWSGROUP
newpr 17 hits
greg newpr 8 hits
ANSWERS
newpr 68 hits
greg newpr 56 hits
% question 2 : I got this code from a friend who has worked on another topic , and I was going to use it
Again, not recommended
% 3-I do not know the difference and why newff is obsolete here , I wish you would tell me
NEWFF is obsolete because MATLAB replaced it 5 years ago. Previously,
NEWFIT for curve-fitting and regression. It automatically calls NEWFF
NEWPR for pattern-recognition and classification. It also automatically calls NEWFF
>> help newpr
newpr Create a pattern recognition network.
Obsoleted in R2010b NNET 7.0. Last used in R2010a NNET 6.0.4.
Similarly for newfit and newff.
=========================
Currently, MATLAB offers
FITNET for curve-fitting and regression. It automatically calls FEEDFORWARDNET
PATTERNNET for pattern-recognition and classification. It also automatically calls FEEDFORWARDNET
You can obtain the full online documentation of any function using help and doc in the command line. The biggest problem is that the corresponding examples tend to pretty Mickey-Mouse. However, they provide the basics from which you can start. On the other hand the scripts from the nntool are too detailed and do not emphasize the most important commands.
Finally, you can search the NEWSGROUP and ANSWERS for the examples in my posts. If you have any problems with them you can always alert me via email that you have posted a follow-up comment or question. I do not give direct advice via email.
% 4- I get this as an advice, thank you % % 5- which one do you intend ? % % 6- it's a problem I should solve asap % % 7- well each question has it's own problem , I could not follow all , % specially with the error that I get , I yet could not find an answer for % that myself
Finally, I suggest using patternnet instead of the obsolete newpr. However, if you want to go with newpr, see my suggestions above.
Hope this helps.
Greg
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!