R caret package rfe error - "argument is not interpretable as logical" -


i trying use rfecontrol , rfe simple feature selection task using svm. input file small , has 20 features 414 samples. input can found here [https://www.dropbox.com/sh/hj91gd06dbbyi1o/aabthpup4ki85onsqbigh_isa?dl=0].

ignoring warning, not understand error below understand maximize takes value when metric==rmse , i, however, have metric==accuracy performing classification (reference: 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 not interpretable logical in addition: warning message: in if (maximize) which.max(x[, metric]) else which.min(x[, metric]) : condition has length > 1 , first element used 

the code follows:

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") 

thanks in advance.

there multiple errors in code.

  1. you creating new class2, not selecting y, selecting class
  2. you using formula notation in rfe , x , y notation. leads error get. either use x , y or use formula notation. check example code below.

the code below works:

library("caret") sensor6data_2class <- read.csv("svm_2labels.csv") sensor6data_2class$class <- as.factor(sensor6data_2class$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) set.seed("1298356") model_train <- rfe(x = trainx,                     y = y,                     sizes = c(10,11),                     metric = "accuracy" ,                     rfecontrol = ctrl) set.seed("1298356") model_train_form <- rfe(class ~ zcr + energy + spectralc + spectrals + spectrale + spectralf + spectralr + mfcc1 + mfcc2 + mfcc3 + mfcc4 + mfcc5 + mfcc6 + mfcc7 + mfcc8 + mfcc9 + mfcc10 + mfcc11 + mfcc12 + mfcc13,                          data = training,                         sizes = c(10,11),                          metric = "accuracy",                         rfecontrol = ctrl) 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -