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 (将#修改为@)