我想使用caret :: rfe()函数执行特征选择,使用bayesglm模型。
由于这个模型没有在您传递给rfeControl的函数中实现,我使用lmFuncs作为模板创建了它:
bayesglmFuncs <- lmFuncs
bayesglmFuncs$fit <- function (x, y, first, last, ...)
{
tmp <- if (is.data.frame(x)) x
else as.data.frame(x)
tmp$y <- y
bayesglm(y ~ ., family=binomial(link='logit'), data = tmp)
}
然后:
rfecontrol <- rfeControl(functions=bayesglmFuncs, method="repeatedcv", number=10, repeats = 3)
model.sel <- rfe(Data[,c(2:8,10,11,13:17)], Data[,12], rfeControl = rfcontrol)
不幸的是,它失败并出现此错误:
{:task 1 failed - “undefined columns selected”
出错
这是数据结构(uterus.atonia是dep。变量):
str(Data[,c(2:8,10,11,12,14:17)])
'data.frame': 50 obs. of 14 variables:
$ prev.pregs : int 0 1 0 1 2 1 1 2 2 2 ...
$ abortions : int 0 0 0 0 0 0 0 0 0 0 ...
$ born.at.term : int 0 1 0 1 2 1 1 2 2 2 ...
$ gest.days : int 272 273 266 273 281 273 283 254 273 289 ...
$ delivery.type : Factor w/ 2 levels "ps","tc urgente": 1 1 1 1 1 1 1 1 1 1 ...
$ mother.age : int 35 37 25 38 40 41 38 37 35 35 ...
$ oxytocin : Factor w/ 2 levels "no","si": 1 1 2 1 2 2 2 2 1 2 ...
$ prom : Factor w/ 2 levels "no","si": 1 1 2 1 1 1 1 2 1 1 ...
$ labor.induction : Factor w/ 2 levels "no","si": 1 1 2 1 1 1 1 2 1 2 ...
$ uterus.atonia : Factor w/ 2 levels "no","si": 1 1 1 1 1 1 1 1 1 1 ...
$ anestesia.type.locale : Factor w/ 2 levels "no","yes": 2 2 1 2 1 1 1 2 2 2 ...
$ anestesia.type.combinata: Factor w/ 2 levels "no","yes": 1 1 2 1 2 2 2 1 1 1 ...
$ anestesia.type.epidurale: Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
$ anestesia.type.spinale : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...