r - 插入符号 : undefined columns selected

标签 r r-caret

我一直试图让下面的代码在插入符号中运行,但出现错误。谁能告诉我如何解决它。

Error in [.data.frame(data, , lvls[1]) : undefined columns selected


library(tidyverse)
library(caret)

mydf <- iris

mydf <- mydf %>% 
  mutate(tgt = as.factor(ifelse(Species == 'setosa','Y','N'))) %>% 
  select(everything(), -Species)

trainIndex <- createDataPartition(mydf$tgt, p = 0.75, times = 1, list = FALSE)
train <- mydf[trainIndex,]
test <- mydf[-trainIndex,]

fitControl <- trainControl(method = 'repeatedcv',
                       number = 10,
                       repeats = 10,
                       allowParallel = TRUE,
                       summaryFunction = twoClassSummary)

fit_log <- train(tgt~.,
             data = train,
             method = "glm",
             trControl = fitControl,
             family = "binomial")

最佳答案

您需要使用 classProbs = TRUE在您的控制功能中。 ROC 曲线基于类概率,错误是汇总函数没有找到这些列。

关于r - 插入符号 : undefined columns selected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44925565/

相关文章:

使用 .SD 检索 lapply 内的列名

r - 使用火车时出现插入符错误 : "Something is wrong; all the RMSE metric values are missing"

r - glmnet 拒绝预测

r - "exclude"`factor()` 中的参数不起作用

r - 为什么 mapply 不能按预期使用转换?

检索插入符号中保留折叠的预测

R插入符号在训练后重命名data.table中的列

r-caret:具有 n 维输出的自定义模型

r - 用几种不同的格式解析耗时/时间跨度/持续时间

r - 插入符号中的折叠与训练错误