Input and target have different number of sampel

94 ビュー (過去 30 日間)
Oman Wisni
Oman Wisni 2018 年 11 月 14 日
回答済み: SULE 2023 年 12 月 29 日
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

採用された回答

Greg Heath
Greg Heath 2019 年 3 月 21 日
Train and TTrain have to be transposed.
Hope this helps.
THANK YOU FOR FORMALLY ACCEPTING MY ANSWER
Greg
  1 件のコメント
Oman Wisni
Oman Wisni 2019 年 3 月 21 日
Thank you for the answer Mr.Greg

サインインしてコメントする。

その他の回答 (2 件)

Osama Tabbakh
Osama Tabbakh 2019 年 3 月 20 日
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 件のコメント
Oman Wisni
Oman Wisni 2019 年 3 月 21 日
Thank you for the answer sir,

サインインしてコメントする。


SULE
SULE 2023 年 12 月 29 日
function [ ye yv ] = neuralnetwork(input,target,training_rate,n1,n2, lrate)
%NEURALNETWORK Summary of this function goes here
% Detailed explanation goes here
% %70 training ve %30 validation
noofdata=size(input,1);
ntd=round(noofdata*training_rate);
xt=input(1:ntd,:);
xv=input(ntd+1:end,:);
yt=target(1:ntd);
yv=target(ntd+1:end);
xt=xt';
xv=xv';
yt=yt';
yv=yv';
xtn=mapminmax(xt);
xvn=mapminmax(xv);
[ytn, ps]=mapminmax(yt);
yv=mapminmax(yv);
net=newff(xtn,ytn,[n1,n2],(''),'trainlm');
net.trainParam.lr=lrate;
net.trainParam.epochs=10000;
net.trainParam.goal=1e-20;
net.trainParam.show=NaN;
net=train(net,xtn,ytn);
yen=sim(net,xvn);
ye=mapminmax('reverse',yen,ps);
ye=ye';
yv=yv';
end
This code not work and i do not know why.I need help
??? Error using ==> trainlm at 109
Inputs and targets have different numbers of samples.

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by