R Caret's rfe [Error in { : task 1 failed - “rfe is expecting 184 importance values but only has 2”]

怎甘沉沦 提交于 2019-12-04 12:57:09

It seems that you might have highly correlated predictors.
Prior to feature selection you should run:

crrltn = findCorrelation(correlations, cutoff = .90)
if (length(crrltn) != 0)
  x <- x[,-crrltn]

If after this the problem persists, it might be related to high correlation of the predictors within folds automatically generated, you can try to control the generated folds with:

set.seed(12213)
index <- createFolds(y, k = 10, returnTrain = T)

and then give these as arguments to the rfeControl function:

lmctrl <- rfeControl(functions = lmFuncs, 
                     method = "repeatedcv", 
                     index = index,
                     verbose = TRUE)

set.seed(111333)
lrprofile <- rfe( z , x,
                  sizes = sizes,
                  rfeControl = lmctrl)

If you keep having the same problem, check if there are highly correlated between predictors within each fold:

for(i in 1:length(index)){
  crrltn = cor(x[index[[i]],])     
  findCorrelation(crrltn, cutoff = .90, names = T, verbose = T)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!