Model is empty, SVM in e1071 package

情到浓时终转凉″ 提交于 2019-12-10 14:32:00

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/24163316/model-is-empty-svm-in-e1071-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!