Caret:选择未定义的列

时间:2017-07-05 11:55:45

标签: r r-caret

我一直试图让下面的代码在插入符号中运行但是得到了错误。谁能告诉我怎么麻烦拍它。

  

[.data.frame中的错误(data ,, lvls [1]):选择了未定义的列

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")

2 个答案:

答案 0 :(得分:7)

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

答案 1 :(得分:0)

使用数据= data.frame(xxxxx)。如下面的示例

fit.cart <-train(条件〜。,data = data.frame(trainset),method =“ rpart”,metric = metric,trControl = control)