can some one tell me what am i doing wrong?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Narges Sedre
el 26 de Nov. de 2018
Comentada: Walter Roberson
el 27 de Nov. de 2018
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 comentarios
Respuesta aceptada
Walter Roberson
el 27 de Nov. de 2018
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 comentarios
Walter Roberson
el 27 de Nov. de 2018
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!