Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何计算R插入符号包中每个折叠的AUC?_R_Machine Learning_R Caret - Fatal编程技术网

如何计算R插入符号包中每个折叠的AUC?

如何计算R插入符号包中每个折叠的AUC?,r,machine-learning,r-caret,R,Machine Learning,R Caret,我需要计算每个折叠的混淆矩阵和AUC。在R中使用插入符号包。 对于混淆矩阵,一切正常。但对于计算AUC,我有一个错误: 选择未定义的列 有没有其他方法来计算AUC df$ximp<-df$ximp[sample(nrow(df$ximp)),] #Create 5 equally size folds folds <- cut(seq(1,nrow(df$ximp)),breaks=5,labels=FALSE) #Perform 5fold cross validation -

我需要计算每个折叠的混淆矩阵和AUC。在R中使用插入符号包。 对于混淆矩阵,一切正常。但对于计算AUC,我有一个错误: 选择未定义的列 有没有其他方法来计算AUC

df$ximp<-df$ximp[sample(nrow(df$ximp)),]

#Create 5 equally size folds
folds <- cut(seq(1,nrow(df$ximp)),breaks=5,labels=FALSE)

#Perform 5fold cross validation - random forest
importance=list()
for(i in 1:5){
  #Segement your data by fold using the which() function 
  testIndexes <- which(folds==i,arr.ind=TRUE)
  testData <- df$ximp[testIndexes, ]
  trainData <- df$ximp[-testIndexes, ]
  rf_fit <- train(Vital_status ~ ., 
                  data = trainData, 
                  method = "ranger",
                  importance = 'permutation')
  pred=predict(rf_fit, testData,type="prob")
  paste("###### fold 1")
  print(confusionMatrix(pred, testData$Vital_status))
  a=varImp(rf_fit)
  importance[[i]] <- a
  auc(testData$Vital_status,as.numeric(pred[2]),direction="<", levels = levels(df$ximp$Vital_status))
  par(pty="s")
  roc(testData$Vital_status,as.numeric(pred),plot = TRUE,precent=TRUE,print.auc=TRUE,legacy.axes=TRUE,percent=TRUE,
      col="#4daf4a",main = paste("ROC of random forest fold",i))
}

df$ximpi如果您使用的是pROC软件包,请参阅如何使用
auc
,我怀疑您没有正确使用它