Receiving Error when Running RFE codes in R

26 views Asked by At

I have a data frame with 1409 rows and 40 columns: one column is the dependent variable (column one), and 39 others are predictors. I ran the following codes of the RFE model using the Caret package on a computer with 6 CPU cores and 64GB of memory. The data frame was named cq.

library(caret)

X <- cq[,c(2:40)] # It is a data frame of predictor variables
Y <- cq[,c(1)] # This is BD

## We normalize the predictors and put them in a data frame

normalization <- preProcess(X)
X <- predict(normalization, X)
X <- as.data.frame(X)

cores<-(detectCores())
registerDoParallel(cores*0.75)

set.seed(10)

# RFE Control parameters
ctrl <- rfeControl(functions = caretFuncs, 
                   method = "repeatedcv",
                   rerank = TRUE,
                   repeats = 5,
                   number= 5,
                   allowParallel = TRUE)
# RFE models
RF_39 <- rfe(x= X, 
             y= Y, 
             sizes = c(1:39),
             method ='rf',
             rfeControl = ctrl,
             tuneGrid = data.frame(mtry=6))

The codes look fine and the caret package has been installed, but I get the following error message, and I cannot solve this problem.

Error in { : task 1 failed - "replacement has 1 row, data has 0"

Please help me how to resolve this error message.

0

There are 0 answers