Reputation: 11
While I'm trying to do feature selection (Using Wrapper Approach) by fscaret
function I got this error:
*Elapsed time: 0.81 0 0.88 NA NA
[1] "Building model has failed or reached timelimit!"
Error: $ operator is invalid for atomic vectors"*
Note: I want to get relevant features for neural network and SVM algorithm as wrapper approach gets relevant features based on the used algorithm.
Here is my code:
library(caret)
library(fscaret)
library(R.methodsS3)
#load data:
mov = read.csv("bank.csv",header=TRUE,sep = ";")
mov$y = as.factor(mov$y)
mov$y = as.numeric(mov$y)
#to convert data(factors) into binary format
dumdmov <- dummyVars("~.", data=mov , fullRank=F)
mov <- as.data.frame(predict(dumdmov,mov))
head(mov)
#train and test set
trainIndex <- createDataPartition(mov$y, p = .70, list = FALSE, times = 1)
head(trainIndex)
mov_train <- mov[ trainIndex,]
mov_test <- mov[-trainIndex,]
#apply fscaret function
fsmodel2<- c("neuralnet","svmRadial")
results <- fscaret(mov_train, mov_test,installReqPckg = TRUE ,
myTimeLimit = 40, preprocessData=TRUE, classPred = TRUE, regPred = FALSE,
Used.funcClassPred = fsmodel2, with.labels=TRUE,
supress.output=FALSE,no.cores = NULL )
Upvotes: 0
Views: 175
Reputation: 78937
You should use [
not $
.
See here: R Error in x$ed : $ operator is invalid for atomic vectors
For example here:
trainIndex <- createDataPartition(mov$y, p = .70, list = FALSE, times = 1) head(trainIndex)
try:
trainIndex <- createDataPartition(mov[y], p = .70, list = FALSE, times = 1) head(trainIndex)
Upvotes: 2