SVM MATLAB stats give test error

1

The following MATLAB code trains a MATLAB binary classifier given a set of vectors and tests another set of vectors in that 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 without problems. But 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 already looked for NaN values in the training and the test and nothing. This code would normally run under normal conditions. What do I have that might be causing this?

Crosspost: Matlab Stats Svm error in testing

    
asked by anonymous 28.04.2014 / 19:12

1 answer

2

AP has been able to answer in OS :

This should be solvable by keeping my generic solution to this problem in mind.

1) Run the code with dbstop if error occurs

It will now stop on the line you provided:

outclass= glevels(outclass(~unClassified),:);

2) Check for possible solutions.

In this case, I assume that glevels and outclass are the two variables. The next thing to do would be to carefully examine everything that could be an index.

Inside out:

The first index is ~unClassified , as the ~ operation did not fail, it is safe to say that this is now a logical vector.

The second and lastIndex is outclass(~unClassified) , it is more likely that not only numbers like 1,2,3, ... or true / false values of this one will be constituted.

The test if the values are all valid is quite simple, one of the two should contain:

To confirm that the x values are logical: class(x) should return "logic" To confirm that the x values are real positive integers: isequal(x, max(1,round(abs(x)))) should return 'true'.

    
23.05.2017 / 14:37