while executing the following matlab code, I have an error like, "Index exceeds matrix dimensions" and "Error in classification (line 34) if test_targetsl(i,1)==1 && result(i,1)==1". plz help me to find the solution to this error.
Afficher commentaires plus anciens
clear;
Data='clusteredData.csv';
CData=csvread(Data);
%Output evaluation variables.
TP=0;
TN=0;
FP=0;
FN=0;
%take out data for mining.
train_data=CData(1:1545,1:2)'
train_targets=CData(1:1545,3)'
%take out data for testing.
test_data=CData(1546:4417,1:2)'
test_targets=CData(1546:4417,3)'
%call C5.0 classification method to create the tree.
[tree,discrete_dim]=C5_0(train_data,train_targets,1)
disp('classify test samples using the tree')
%use the tree built using training data to examine test data. input:test
%data, number of records in test data, tree, discrete_dim indicates number
%of classes i.e. 2, 1 or 2.
result=use_tree(test_data,1:size(test_data,2),tree,discrete_dim,unique(train_targets));
%transpose the matrix
result'
%restore the result to its original state.
resultl=result'
test_data=test_data'
test_targetsl=test_targets'
[S,dim]=size(test_targetsl);
desResult=zeros(S,1);
figure(1)
for i=1:S
if test_targetsl(i,1)==1 && result(i,1)==1
TP=TP+1;
plot(test_data(i,1),test_data(i,2),'*g')
hold on
elseif test_targetsl(i,1)==2 && resultl(i,1)==2
TN=TN+1;
plot(test_data(i,1),test_data(i,2),'om')
hold on
elseif test_targetsl(i,1)==1 && result1(i,1)==2
FN=FN+1;
plot(test_data(i,1),test_data(i,2),'xr')
hold on
elseif test_targetsl(i,1)==2 && result1(i,1)==1
FP=FP+1;
plot(test_data(i,1),test_data(i,2),'+y')
hold on
end
end
title('Test data after classification');
grid on
axis equal
for i=1:S
if result1(i,1)==1
desResult(i,1)='A';
else
desResult(i,1)='N';
end
end
classifiedReslut=[test_data test_targets' result'];
dlmwrite('classifiedReslut.txt',classifiedReslut,'delimiter','\t');
dlmwrite('NormalabnormalclassifiedReslutReslut.txt',string(desResult),'delimiter','\t');
disp('True Negative')
TN
disp('True Positive')
TP
disp('False Negative')
FN
disp('False Positive')
FP
disp('Detection Rate')
DetectionRate=(TP)/(TP+FP)
disp('False Alarm')
FalseAlarm=(FP)/(FP+TN)
disp('Accuracy')
Accuracy=(TP+TN)/(TP+TN+FP+FN)
2 commentaires
Walter Roberson
le 21 Nov 2017
We do not have your data to test with. You will need to learn how to use the debugger.
pramod chaudhary
le 22 Nov 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!