我有一个大约 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 上测试模型时出现问题,该模型是结构化的exactly就像训练集一样:
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 !
非常欢迎提出想法。