1
The following MATLAB code trains a binary classifier of MATLAB given a set of vectors and tests another set of vectors in this classifier:
%Número mínimo de iterações
optSVM = statset('MaxIter', 1000000);
%treino do classificador
SVMtrainModel = svmtrain(training_vectors_matrix(:,2:end), training_vectors_matrix(:,1), 'kernel_function' , 'linear', 'options', optSVM, 'tolkkt', 0.01);
%lê os vetores de teste
TestV = csvread(test_file);
%Testa os vetores no classificador
TestAttribBin = svmclassify(SVMtrainModel, TestV(:,2:end))
That is, it is a simple code that would run smoothly. Only here the training works normally, but when I test, MATLAB gives me the following error:
Subscript indices must either be real positive integers or logicals.
Error in svmclassify (line 140)
outclass= glevels(outclass(~unClassified),:);
What would be the cause of this problem? I have looked for Nan values in training and testing and nothing. This code would normally run under normal conditions. What I have that might be causing this?
Crosspost: Matlab Stats Svm error in testing
What
TestV(:,2:end)
returns? By the error description it seems that the SVM code is not able to filter the elements inTestV
. Can I provide a functional example (including the data)? Hence I can test here.– Luiz Vieira
Hello Luiz. First thank you for the answer. Testv is a matrix with the test vectors. In the first column of Testv I have the real class of vectors (later used to calculate accuracy) and, from the second column on, we have the characteristic vectors. That is why Testattribbin = svmclassify(Svmtrainmodel, Testv(:,2:end)) tests the Testv matrix characteristic vectors in the Svmtrainmodel binary classifier. I will make the data and source available in a few moments. Thanks again.
– mad
Not at all @Mad. Well, I’m sorry if the question is too obvious, but you checked if the dimension of the characteristic vectors is the same in the training and test data, right?
– Luiz Vieira
Hi Luiz. These same vectors of characteristics have been converted to the format of Libsvm and in Libsvm is running normally the classification. However your question is very good so I need to check. Thanks again.
– mad