Classificaion with fitcsvm in matlab produces an error

Viewed 1029

I had tried the following code

clear all;close all;
data =  [27 9   2
11.6723281  28.93422177 2
25  9   2
23  8   2
5.896096039 23.97745722 1
21  6   2
21.16823369 5.292058423 2
4.242640687 13.43502884 1
22  6   2];
Attributes = data(:,1:2);
Classes = data(:,3);
train = [1 3 4 5 6 7];
testInds = [2 8 9];
test1 = data(testInds,1:2);
YTest =data(testInds,3);
%%# Train
svmStruct = svmtrain(Attributes(train,:),Classes(train),'ShowPlot',true);

 SVMModel = fitcsvm(Attributes(train,:),Classes(train))
 classOrder = SVMModel.ClassNames
sv = SVMModel.SupportVectors;
figure
gscatter(data(:,1),data(:,2),Classes)
hold on
plot(sv(:,1), sv(:,2),'ko','MarkerSize',10)
legend('good','bad','Support Vector')
hold off
[label,score] = predict(SVMModel,test1);
% [predict_label, accuracy, prob_estimates] = predict(SVMModel,test1)
table(YTest(1:2),label(1:2),score(1:10,2),'VariableNames',...
    {'TrueLabel','PredictedLabel','Score'})

I tried the above code. First two column are my data and last column is the group id. SVMModel is the classification. I'm getting error as

Index exceeds matrix dimensions.

Error in Untitled (line 34) table(YTest(1:2),label(1:2),score(1:10,2),'VariableNames',... I tried to test an instance. But both statements produces an error

[label,score] = predict(SVMModel,test);
 label           = svmclassify(SVMModel, test);
1 Answers
Related