如何解决AUC 函数中的初始化向量越界
我正在尝试使用 AUC 对决策树进行交叉验证。这些是我正在使用的功能:
.cvFolds <- function(Y,V) {
Y0 <- split(sample(which(Y == 0)),rep(1:V,length = length(which(Y == 0))))
Y1 <- split(sample(which(Y == 1)),length = length(which(Y == 1))))
folds <- vector("list",length = V)
for (v in seq(V)) folds[[v]] <- c(Y0[[v]],Y1[[v]])
return(folds)
}
.doFit <- function(V,folds,train) {
set.seed(v)
ycol <- which(names(train) == y)
params <- list(x = train[-folds[[V]],-ycol],y = as.factor(train[-folds[[V]],ycol]),xtest = train[folds[[V]],-ycol])
fit <- do.call(randomForest,params)
pred <- fit$test$Votes[,2]
return(pred)
}
这是计算概率的函数:
iid_example <- function(train,y = "V1",V = 10,seed = 1) {
set.seed(seed)
folds <- .cvFolds(Y = train[,c(y)],V = V)
# Generate CV predicted values
cl <- makeCluster(detectCores())
registerDoParallel(cl)
predictions <- foreach(v = 1:V,.combine = "c",.packages = c("randomForest")) %dopar% .doFit(v,train)
stopCluster(cl)
predictions[unlist(folds)] <- predictions
# Get CV AUC
runtime <- system.time(res <- ci.cvAUC(predictions = predictions,labels = train[,folds = folds,confidence = 0.95))
print(runtime)
return(res)
}
res <- iid_example(train = datos,seed = 1)
当我尝试运行它时,出现以下错误:
Y0[[v]] 越界
我正在尝试调整函数的参数化,但我不明白为什么它越界了。感谢您的帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。