【问题标题】:Glm with caret package producing "missing values in resampled performance measures"带有插入符号包的 Glm 产生“重采样性能测量中的缺失值”
【发布时间】:2020-12-12 16:46:27
【问题描述】:

我从这个 Stack Overflow 问题中获得了以下代码。 caret train() predicts very different then predict.glm()

以下代码产生错误。 我正在使用插入符号 6.0-52。

library(car); library(caret); library(e1071)

#data import and preparation
data(Chile)
chile        <- na.omit(Chile)  #remove "na's"
chile        <- chile[chile$vote == "Y" | chile$vote == "N" , ] #only "Y" and "N" required
chile$vote   <- factor(chile$vote)      #required to remove unwanted levels
chile$income <- factor(chile$income)  # treat income as a factor

tc <- trainControl("cv", 2, savePredictions=T, classProbs=TRUE,
               summaryFunction=twoClassSummary)  #"cv" = cross-validation, 10-fold
fit <- train(chile$vote ~ chile$sex            +
           chile$education      +
           chile$statusquo      ,
         data      = chile    ,
         method    = "glm"    ,
         family    = binomial ,
         metric = "ROC",
         trControl = tc)    

运行此代码会产生以下错误。

Something is wrong; all the ROC metric values are missing:
  ROC           Sens             Spec       
 Min.   : NA   Min.   :0.9354   Min.   :0.9187  
 1st Qu.: NA   1st Qu.:0.9354   1st Qu.:0.9187  
 Median : NA   Median :0.9354   Median :0.9187  
 Mean   :NaN   Mean   :0.9354   Mean   :0.9187  
 3rd Qu.: NA   3rd Qu.:0.9354   3rd Qu.:0.9187  
 Max.   : NA   Max.   :0.9354   Max.   :0.9187  
 NA's   :1                                      
Error in train.default(x, y, weights = w, ...) : Stopping
In addition: Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo,  :
  There were missing values in resampled performance measures.

有没有人知道问题是什么或可以重现/不重现此错误。我已经看到此错误消息的其他答案,说这与在每个交叉验证折叠中没有类的表示有关,但这不是问题,因为折叠数设置为 2。

【问题讨论】:

  • 你解决了吗?我面临着类似的问题,但以下答案都没有帮助我。

标签: r-caret


【解决方案1】:

看来我需要安装和加载 pROC 包。

install.packages("pROC") 库(pROC)

【讨论】:

    【解决方案2】:

    你应该使用安装

    install.packages("caret", dependencies = c("Imports", "Depends", "Suggests"))

    这获得了大多数默认包。如果缺少特定的建模包,代码通常会提示您安装它们。

    【讨论】:

      【解决方案3】:

      我知道我迟到了,但我认为你需要在火车控制中设置classProbs = TRUE

      【讨论】:

        【解决方案4】:

        您在使用参数method = "glm", family = binomial 时使用逻辑回归。 在这种情况下,您必须确保目标变量 (chile$vote) 只有 2 个因子水平,因为逻辑回归只执行二元分类。

        如果目标有两个以上的标签,那么你必须设置family = "multinomial"

        【讨论】:

          猜你喜欢
          • 2015-10-18
          • 2015-01-05
          • 1970-01-01
          • 2018-06-26
          • 2019-01-04
          • 2018-10-03
          • 2020-12-12
          • 2016-12-08
          • 2021-03-05
          相关资源
          最近更新 更多