【发布时间】:2015-01-21 07:00:17
【问题描述】:
我使用 SVM 进行分类,我将我的数据集分为两个 CSV 文件,一个是训练集(70% 的数据),另一个是测试集(30% 的数据)。 当我在训练集上使用预测时,我得到了答案,但在测试集上显示错误 我正在使用 e1071 包
程序如下
Train <- read.csv("Train.csv")
Test <- read.csv("Test.csv")
x_Train <- subset(Train,select=-Class)
y_Train <- Train$Class
model <- svm(Class ~., data=Train)
pred=predict(model, x_Train) #working well
table(pred,y_Train)
x_Test <- subset(Test,select=-Class)
y_Test <- Test$Class
pred <- predict(model, x_Test) #getting_error
Error in scale.default(newdata[, object$scaled, drop = FALSE], center = object$x.scale$"scaled:center", :
length of 'center' must equal the number of columns of 'x'
请您找出问题所在...?
【问题讨论】:
-
在您的示例中,您创建了 x_Test 对象,但您在 x_test 对象上进行了预测。大写字母会有所不同。
-
随着更改也出现错误:scale.default(newdata[, object$scaled, drop = FALSE], center = object$x.scale$"scaled:center", : 'center' 的长度必须等于 'x' 的列数
-
没有数据很难找出问题所在。