MATLAB: Can some one tell me what am i doing wrong

machine learningneural networkneural networks

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
%

Best Answer

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.