0
我正嘗試使用rfeControl和rfe進行簡單的使用svm的功能選擇任務。輸入文件很小,有20個特徵,414個樣本。輸入可以在這裏找到[https://www.dropbox.com/sh/hj91gd06dbbyi1o/AABTHPuP4kI85onSqBiGH_ISa?dl=0]。R符號包rfe錯誤 - 「參數不可理解爲邏輯」
忽略警告,我不明白下面的錯誤是,因爲我明白當衡量指標== RMSE和我時,最大化的價值,但是,具有指標==準確性,因爲我正在執行分類(參考: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")
感謝。
感謝@phiver。也爲我工作得很好!如果我可能會問一個後續問題,我試圖用預測函數預測輸出,使用測試數據,並且不輸出所有樣本的預測結果。任何想法爲什麼?我有代碼和輸出在跟進答案。謝謝! – tacqy2