Asked by phdcomputer Eng
on 22 Jun 2019

I wrote a code for classification by using 5 classifiers and at the end I used voting this code is for initia defining of train and test data:

clear all

close all

clc

load liver.mat;

data=Liver;

[n,m]=size(data);

rows=(1:n);

test_count=floor((1/6)*n);

sum_ens=0;sum_result=0;

test_rows=randsample(rows,test_count);

train_rows=setdiff(rows,test_rows);

test=data(test_rows,:);

train=data(train_rows,:);

xtest=test(:,1:m-1);

ytest=test(:,m);

xtrain=train(:,1:m-1);

ytrain=train(:,m);

I put the resault of each classifier in out 1-5 and then aggregate them in output and compared output with test labels :

out1 = majorityvote(tt(1,:));

out2 = majorityvote(tt(2,:));

out3 = majorityvote(tt(3,:));

out4 = majorityvote(tt(4,:) );

out5 = majorityvote(tt(5,:) );

output=[out1,out2,out3,out4,out5];

for i=1:test_count

if(output(i)==1 && ytest(i)==1)

tp_ens=tp_ens+1;

end

if(output(i)==0 && ytest(i)==0)

tn_ens=tn_ens+1;

end

if(output(i)==0 && ytest(i)==1)

fp_ens=fp_ens+1;

end

if(output(i)==1 && ytest(i)==0)

fn_ens=fn_ens+1;

end

end

this codes doesn't have any problems with other datasets in this part but for the liver data (attached) It shows this error:

Index exceeds matrix dimensions.

Error in pimaclassify_new (line 174)

if(output(i)==1 && ytest(i)==1)

Maybe because the number of test_count for specified number of rows of data were obtained 5 so comparing them with test labels was true but for liver data which have different number of rows , this comparing shows error.

Should I change the sizes of outputs of classifiers or the size of test data or test_count?

I'll be grateful to have your opinions about fixing the error.

Thanks

Opportunities for recent engineering grads.

Apply Today
## 6 Comments

## dpb (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/468377-how-to-compare-matrices-with-different-dimensions#comment_717230

## phdcomputer Eng (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/468377-how-to-compare-matrices-with-different-dimensions#comment_717627

## Bob Nbob (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/468377-how-to-compare-matrices-with-different-dimensions#comment_717668

## Guillaume (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/468377-how-to-compare-matrices-with-different-dimensions#comment_717681

## Bob Nbob (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/468377-how-to-compare-matrices-with-different-dimensions#comment_717731

## Guillaume (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/468377-how-to-compare-matrices-with-different-dimensions#comment_717753

Sign in to comment.