can some one tell me what am i doing wrong?
1 次查看(过去 30 天)
显示 更早的评论
well iam trying to find the training error and test error of a database
something is wrong whit my code cause y1 and y2 arry are all 1 but i dont know what is the problem can someone tell me how else can i find the test error i tried H = numel(find(trainingset' ==y1)) but this error came up Error using ==
Matrix dimensions must agree.
clc
clear all
close all
filename='FIFA5.xlsx';
A =xlsread(filename);
[m,n]=size(A);
T= A(:,1);
data= A(:,(2:end));
rows80=int32(floor(0.8 * m));
trainingset=A(1:rows80,:);
testset=A(rows80+1:end,:);
t=trainingset(1:rows80,1);
t_test=A(rows80+1:end,1);
net= newff(trainingset',t');
y=sim(net,trainingset');
%net.trainParam.epoch=20;
net= train(net,trainingset',t');
y=sim(net,trainingset');
y_test=sim(net,testset');
p=0;
y1=hardlim(y');
y2= hardlims(y_test);
for(i=1:size(t,1))
if(t(i,:)==y1(i,:))
p=p+1;
end
end
trainerror =100*p/size(trainingset,1);
e=0;
y2=hardlim(y_test');
for(j=1:size(t_test,1))
if(t_test(j,:)==y2(j,:))
e=e+1;
end
end
testerror=100*e/size(t_test,1);
%[m, n] = size(trainingset);
%H = numel(find(trainingset' ==y1))
% errTrainNum = m - H;
%
% x = 100 / m;
%
% errorOfTrain = (x * errTrainNum) / 100
%
0 个评论
采纳的回答
Walter Roberson
2018-11-27
t=trainingset(1:rows80,1);
so t is one column
net= train(net,trainingset',t');
so you are constructing a neural network that has one output for each input.
y=sim(net,trainingset');
The result of simulation will be 1 output for each sample in trainingset.
y1=hardlim(y');
The output of hardlim() has the same size as the input, so y1 will have one output for each sample in training set.
find(trainingset' ==y1)
trainingset is a 2D array with multiple attributes per sample. You are trying to use == to compare all of those multiple attributes per sample to something that has one value per sample.
In R2016a and earlier, this is always a mistake. In R2016b and later, it will not cause an error if the dimensions match along one edge and the other edge has a singleton dimension.
I did not track through the various transposes to determine whether the edges can potentially match.
4 个评论
Walter Roberson
2018-11-27
In terms of your original code, instead of
t=trainingset(1:rows80,1);
you would use
t=trainingset(1:rows80,:);
You would get out a pretty useless network, but it should allow the ill-advised
H = numel(find(trainingset' ==y1))
to proceed.
I would put it to you that what you should be doing is instead
trainingset=A(1:rows80,2:end);
testset=A(rows80+1:end,2:end);
t=A(1:rows80,1);
t_test=A(rows80+1:end,1);
after which you would use
H = nnz(t(:) ==y1(:))
The data you train on should never include the target information, and the way you know your success is by comparing the simulated target to the known target rather than by comparing the simulated target to the full set of samples like you were doing.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!