我正在尝试将 rfeControl 和 rfe 用于使用 svm 的简单特征选择任务。输入文件很小,有 20 个特征和 414 个样本。输入可以在这里找到 [ https://www.dropbox.com/sh/hj91gd06dbbyi1o/AABTHPuP4kI85onSqBiGH_ISa?dl=0]。
忽略警告,我对以下错误的不理解是,据我了解,当 metric==RMSE 时最大化取值,但是,我在执行分类时具有 metric==Accuracy(参考:https ://github.com /topepo/caret/blob/master/pkg/caret/R/rfe.R):
Error in if (maximize) which.max(x[, metric]) else which.min(x[, metric]) :
argument is not interpretable as logical
In addition: Warning message:
In if (maximize) which.max(x[, metric]) else which.min(x[, metric]) :
the condition has length > 1 and only the first element will be used
代码如下:
library("caret")
library("mlbench")
sensor6data_2class <- read.csv("/home/sensei/clustering/svm_2labels.csv")
sensor6data_2class <- within(sensor6data_2class, Class <- as.factor(Class))
sensor6data_2class$Class2 <- relevel(sensor6data_2class$Class,ref="1")
set.seed("1298356")
inTrain <- createDataPartition(y = sensor6data_2class$Class, p = .75, list = FALSE)
training <- sensor6data_2class[inTrain,]
testing <- sensor6data_2class[-inTrain,]
trainX <- training[,1:20]
y <- training[,21]
ctrl <- rfeControl(functions = rfFuncs , method = "repeatedcv", number = 5, repeats = 2, allowParallel = TRUE)
model_train <- rfe(x = trainX, y = y, sizes = c(10,11), metric = "Accuracy" , Class2 ~ ZCR + Energy + SpectralC + SpectralS + SpectralE + SpectralF + SpectralR + MFCC1 + MFCC2 + MFCC3 + MFCC4 + MFCC5 + MFCC6 + MFCC7 + MFCC8 + MFCC9 + MFCC10 + MFCC11 + MFCC12 + MFCC13, rfeControl = ctrl, method="svmRadial")
提前致谢。