Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model is empty, SVM in e1071 package

I have a matrix of N examples x 765 features. To this, there is a vector of N labels for each of those examples.

I am trying to use SVM to classify them and make predictions. It worked in one instance when I was splitting the whole data into training and validation using this a manual half-split:

indicator<-1:(length(idx)/2)
training <- idx[indicator]
test<-idx[-indicator]

However, if I try to randomize the halves out of each class in the loop by using this:

indicator<-sample(idx, trunc(length(idx)/2))
training <- idx[indicator]
test<-idx[-indicator]

I get the following error when calling:

svm.model <- svm(x=training,y=trainlabels)

Error in predict.svm(ret, xhold, decision.values = TRUE) : Model is empty!

The dimensions of the matrix and the length of the labels are perfectly fine, the svm() call is what stops working out of the blue.

trainlabels is a "factor" with the labels, svmTraining is a subset of the matrix.

like image 352
user3507046 Avatar asked Jun 11 '14 12:06

user3507046


1 Answers

I've got that error once, the reason was that all the labels were the same, and if nothing is specified, svm tries to perform two-class classification. If, say 90% of the labels are A and you pick randomly a half, your are likely getting only As.

like image 167
Salvy Avatar answered Oct 13 '22 11:10

Salvy