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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With