型号为空,SVM在e1071封装中 [英] Model is empty, SVM in e1071 package

查看:464
本文介绍了型号为空,SVM在e1071封装中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有N个示例x 765个特征的矩阵。为此,每个示例都有一个N个标签的向量。

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

我正在尝试使用SVM对它们进行分类并做出预测。当我使用手动半拆分的方法将整个数据分为训练和验证时,它工作一次:

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!

矩阵的尺寸和标签的长度都很好,svm()的调用是

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是带有标签的因素,svmTraining是矩阵的子集。

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

推荐答案

我一次遇到了该错误,原因是所有标签都相同,并且如果未指定
,则svm尝试执行两个级分类。
如果说90%的标签是A,而您随机选择一半,则您可能只会获得
As。

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.

这篇关于型号为空,SVM在e1071封装中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆