Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscript indices must either be real positive integers or logicals in svmclassify matlab

Tags:

matlab

svm

I am using the matlab's svm classify function. My train and test data have the following dimensions:

>> size(TrainV)

ans =  

   99192         705

>> size(TestV)

ans =

246   705

I have a function that trains a one-versus-one classify with 10 classes (45 binary classifiers). The model can be trained by calling the function below:

Models = SVM_multitrain (TrainV(:, 2:end), TrainV(:, 1), 10); 

I am sending the feature vectors (TrainV(:, 2:end)) and the labels (TrainV(:, 1)) and I am asking the Models to train the combination of couples for 45 classifiers (10). The function runs ok and I can have the following information after the training. For example, I will show the models for the 3rd and 45th binary classifiers.

> Models(3)

ans = 

      SupportVectors: [9x704 double]
               Alpha: [9x1 double]
                Bias: -2.3927 - 0.0001i
      KernelFunction: @linear_kernel
  KernelFunctionArgs: {}
          GroupNames: [20117x1 double]
SupportVectorIndices: [9x1 double]
           ScaleData: [1x1 struct]
       FigureHandles: []

>> Models(45)

ans = 

      SupportVectors: [10x704 double]
               Alpha: [10x1 double]
                Bias: -2.7245 + 0.0000i
      KernelFunction: @linear_kernel
  KernelFunctionArgs: {}
          GroupNames: [22087x1 double]
SupportVectorIndices: [10x1 double]
           ScaleData: [1x1 struct]
       FigureHandles: []

The problem is when I call the function to classify a feature vector, for example, for the first binary classifier.

>>         TestAttribBin = svmclassify(Models(1), TestV(:,2:end))
Subscript indices must either be real positive integers or logicals.

Error in svmclassify (line 140)
outclass = glevels(outclass(~unClassified),:);

What could be the problem? when I apply the same classification procedure to feature vectors extracted in another way this problem does not happen.

like image 275
mad Avatar asked Nov 12 '15 15:11

mad


People also ask

What does subscript indices must either be real positive integers or logicals mean in Matlab?

"Subscript indices must either be real positive integers or logicals." means the index that you are trying to reference does not exist.

Do Matlab array indices have to be positive integers?

Array indices must be positive integers or logical values.


1 Answers

The likely cause of this error is passing complex data to svmclassify. svmclassify only accepts real feature vectors. Indeed, passing a complex data to svmclassify results in outclass being complex and complex values cannot be used for indexing as stated by the error message.

One option may be to encode the imaginary part of your vector into the feature, for example by doubling the length of your feature vectors.

In fact the vast majority of machine learning models are based on the assumption of feature vectors being real eg. artificial neural net, regression trees, svm, etc. Although there might be some extensions in some case.

like image 96
gregswiss Avatar answered Oct 17 '22 06:10

gregswiss