【发布时间】:2014-12-03 14:37:43
【问题描述】:
我有一个大约 500 行和 170 列的数据框。我正在尝试使用 e1071 包中的 svm 运行分类模型。分类变量称为“SEGMENT”,是一个具有 6 个级别的因子变量。数据框中还有其他三个因子变量,其余都是数值型。
data <- my.data.frame
# Split into training and testing sets, training.data and testing.data
.
.
.
fit <- svm(SEGMENT ~ ., data = training.data, cost = 1, kernel = 'linear',
+ probability = T, type = 'C-classification')
模型运行良好。
Parameters:
SVM-Type: C-classification
SVM-Kernel: linear
cost: 1
gamma: 0.0016
Number of Support Vectors: 77
( 43 2 19 2 2 9 )
Number of Classes: 6
Levels:
EE JJ LL RR SS WW
当我尝试在 data.testing 上测试模型时出现问题,该模型的结构完全类似于训练集:
x <- predict(fit, testing.data, decision.values = T, probability = T)
然后事情变得相当壮观:
Error in predict.svm(fit, newdata = testing, decision.values = T, probability = T) :
test data does not match model !
欢迎提出想法。
【问题讨论】:
-
从
str(testing.data)发布输出。我的猜测是因素水平会有所不同。我还猜测,如果您在 SO htat 中搜索该错误文本,您会发现之前已经多次询问和回答了这个问题。 -
请花时间发布reproducible example,以便更轻松地为您提供帮助。否则,我们只是在猜测,可能出了什么问题。
标签: r classification svm modeling