我可能在这里犯了一个非常简单(和愚蠢)的错误,但我无法弄清楚。我正在使用来自 Kaggle ( Digit Recognizer ) 的一些数据,并尝试将 SVM 与 Caret 包一起使用来进行一些分类。如果我只是将标签值作为数字类型train
插入函数,那么 Caret 中的函数似乎默认为回归并且性能很差。所以我接下来尝试使用函数将其转换为因子factor()
并尝试运行 SVM 分类。这是一些代码,我在其中生成了一些虚拟数据,然后将其插入 Caret:
library(caret)
library(doMC)
registerDoMC(cores = 4)
ytrain <- factor(sample(0:9, 1000, replace=TRUE))
xtrain <- matrix(runif(252 * 1000,0 , 255), 1000, 252)
preProcValues <- preProcess(xtrain, method = c("center", "scale"))
transformerdxtrain <- predict(preProcValues, xtrain)
fitControl <- trainControl(method = "repeatedcv", number = 10, repeats = 10)
svmFit <- train(transformerdxtrain[1:10,], ytrain[1:10], method = "svmradial")
我收到此错误:
Error in kernelMult(kernelf(object), newdata, xmatrix(object)[[p]], coef(object)[[p]]) :
dims [product 20] do not match the length of object [0]
In addition: Warning messages:
1: In train.default(transformerdxtrain[1:10, ], ytrain[1:10], method = "svmradial") :
At least one of the class levels are not valid R variables names; This may cause errors if class probabilities are generated because the variables names will be converted to: X0, X1, X2, X3, X4, X5, X6, X7, X8, X9
2: In nominalTrainWorkflow(dat = trainData, info = trainInfo, method = method, :
There were missing values in resampled performance measures.
有人可以告诉我我做错了什么吗?谢谢!