6 views (last 30 days)

clc;

clear;

close all;

tic

load colon.mat

data=colon;

[n,m]=size(data);

%%

%supervised

d=10;

l=1;

t=1;

for i=1:n

if data(i,m)==0

data(i,m)=2;

end

end

data1=[];

data2=[];

for i=1:n

if data(i,m)==1

data1(l,:)=data(i,1:m-1);

l=l+1;

else

data2(t,:)=data(i,1:m-1);

t=t+1;

end

end

if t>l

data1(l:t-1,1:m-1)=0;

else

data2(t:l-1,1:m-1)=0;

end

%computing Distance measures

for i=1: m-1

thisCol1=data1(:,i);

thisCol2=data2(:,i);

a6(i)=fTonimotoDist(thisCol1,thisCol2);

end

%sorting the distances

[A6,indA6]=sort(a6,'descend'); %Tonimoto

%selecting Threshold

datas6=data(:,indA6(1:d));

data6=[datas6 data(:,m)];

%%data6 classify%%tanimoto

[n,m]=size(data6);

for k=1:it

test=data6(test_rows,:);

train=data6(train_rows,:);

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

ytest=test(:,m);

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

ytrain=train(:,m);

[rforest, DT , sk ] = classificationa(xtest,xtrain,ytrain);

[Arforest6(k), ADT6(k) , Ask6(k)] = allaccuracydata(rforest, DT , sk , ytest);

end

averf6=mean(Arforest6);

avedt6=mean(ADT6);

avesk6=mean(Ask6);

x6=[averf6, avedt6 , avesk6];

disp('tanimoto'); disp(x6);

In this code d is the number of selected features(columns) so we use 10 features of the data(colon attached) to classify It, my question is suppose that we want to obtain the average of Arforest (averf6) once for d=10, once for d=20,for d=30,d=40 and d=50 and save the results of averf6 for each of them in one array(forexample a) to plot the array.

how can I save the results of these different runing the program, in one array based on changing in d [10 20 30 40 50], I have problem in this part, and also how to define d that have several values, should I define d as an array forexample d=[10,20,30,40,50]; ?

Thanks

Stephen Cobeldick
on 23 Dec 2019

Edited: Stephen Cobeldick
on 23 Dec 2019

Assuming that those means are scalar values, then a simple loop:

dV = [10,20,30,40,50];

nV = numel(dV);

averf6 = nan(1,nV);

avedt6 = nan(1,nV);

avesk6 = nan(1,nV);

for jj = 1:nV

d = dV(jj);

... your code

averf6(jj) = mean(...)

avedt6(jj) = mean(...)

avesk6(jj) = mean(...)

end

Stephen Cobeldick
on 23 Dec 2019

@phdcomputer Eng: please indent your code consistently. Inconsistently indented code, such as yours, hides the code's structure and hides bugs. You should use the MATLAB editor's default indentation rules, which are applied by default. You can also apply the editor's indentation rules to existing code: select the entire code, the press ctrl+i.

"Do you think this code is wrong?"

The basic concept seems correct, but the inconsistent indentation makes it difficult to tell if it has been implemented correctly.

It is not clear to me why you only preallocated two ouput arrays, although there are apparently six of them. It is also unclear why you hardcoded the preallocated array sizes, even though you have the required array dimensions in the variables nV and it.

dV = [10,20,30,40,50];

nV = numel(dV);

it = 10; % mmoved from inside your loops.

Arf6 = nan(nV,it); % preallocate.

ADT6 = nan(nV,it); % preallocate.

Ask6 = nan(nV,it); % preallocate.

for jj = 1:nV

d = dV(jj);

...

for k = 1:it

...

[Arf6(jj,k), ADT6(jj,k), Ask6(jj,k)] = allaccuracydata(...);

end

end

averf6 = mean(Arf6,2); % mean of each row

avedt6 = mean(ADT6,2); % mean of each row

avesk6 = mean(Ask6,6); % mean of each row

This assumes that the outputs of allaccuracydata are all scalars (which, judging by your code, they appear to be).

Stephen Cobeldick
on 23 Dec 2019

"...sure I use ctrl+i to indent the codes.I hope that the structue will be better."

Your code has exactly the same indentation as before. I cannot follow it.

Please align your code consistently in the MATLAB editor

- select all of the code
- press ctrl + i

Sign in to comment.

phdcomputer Eng
on 23 Dec 2019

Edited: phdcomputer Eng
on 23 Dec 2019

Stephen Cobeldick
on 26 Dec 2019

"should I use these lines in the for k=1:it loop?"

Yes. That is exactly what I showed you. Then you can check what results are generated on each loop iteration, and continue to investigate the iterations that are not generating the results that you expect.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.