【问题标题】:Error while using woe procedure in klaR package在 klaR 包中使用 woe 程序时出错
【发布时间】:2014-11-28 00:07:19
【问题描述】:

我注意到,由于某种原因,klaR 包中的过程 woe 会在尝试在 data.frame 上执行它时产生错误,其中一列是一级因素。这是一个例子:

a<-factor(rep(c("BAD", "GOOD"), 5))
b<-factor(rep(c(1,2), 5))
c<-factor(rep(c(2,3), 5))
d<-factor(rep(1,10))
df<-data.frame(a=a, b=b, c=c, d=d)

现在执行

woe(a~., data = df[,-4])

不会产生任何错误,而

woe(a~., data = df)

将崩溃并出现以下情况:

Error in applywoes(object[[i]], x.fact[, which(names(x.fact) == names(object)[i])]) : 
  Factor Levels do not match!
In addition: Warning message:
In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'

在我看来,问题在于d 只有一个级别作为一个因素。尽管如此,对于这种因素,woe 的定义应该为 0...

这是程序实现中的错误还是(出于某种奇怪的原因)故意行为?

【问题讨论】:

    标签: r


    【解决方案1】:

    我猜这不是故意的行为。根据我在 Git (https://github.com/cran/klaR/blob/master/R/woe.R) 上阅读的内容,诸如“woe.default”之类的函数通常从检查常见错误案例开始。你得到的错误显然是经过检查的。 您应该直接联系这个包背后的团队以获得正确的答案。

    【讨论】:

      猜你喜欢
      • 2016-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 2017-03-08
      • 2021-04-09
      • 1970-01-01
      相关资源
      最近更新 更多