【发布时间】:2018-06-10 22:48:32
【问题描述】:
我正在尝试训练一个支持向量机分类器来进行预测。当我尝试使用经过训练的模型时,出现此错误:测试数据与模型不匹配。我不是为什么会发生这种情况。这是我的代码
# to prepare the training and testing data
dat = data.frame(x = rbind(tmp1, tmp2), y = as.factor(c(rep(1, 300), rep(-1, 300))))
set.seed(1)
train_ind = sample(seq_len(nrow(dat)), size = 500)
train = dat[train_ind, ]
test = dat[-train_ind, ]
# training and prediction
library('e1071')
svmfit = svm(y ~ ., data = train, kernel ='linear', cost = 10, scale = FALSE)
ypred = predict(svmfit, test)
table(predict=ypred, truth = test$y)
【问题讨论】:
标签: testing svm prediction training-data