【问题标题】:wrong model type for regression error in 10 fold cross validation for Naive Bayes using R使用 R 对朴素贝叶斯进行 10 倍交叉验证时回归误差的错误模型类型
【发布时间】:2014-06-14 23:44:28
【问题描述】:

我正在对一些具有 2 个类(0 和 1)的测试数据执行朴素贝叶斯的 10 折交叉验证。 我按照以下步骤操作并出现错误。

data(testdata)

attach(testdata)

X <- subset(testdata, select=-Class)

Y <- Class

library(e1071)

naive_bayes <- naiveBayes(X,Y)

library(caret)
library(klaR)

nb_cv <- train(X, Y, method = "nb", trControl = trainControl(method = "cv", number = 10))

## Error:
## Error in train.default(X, Y, method = "nb", trControl = trainControl(number = 10)) : 
## wrong model type for regression


dput(testdata)

structure(list(Feature.1 = 6.534088, Feature.2 = -19.050915, 
Feature.3 = 7.599378, Feature.4 = 5.093594, Feature.5 = -22.15166, 
Feature.6 = -7.478444, Feature.7 = -59.534652, Feature.8 = -1.587918, 
Feature.9 = -5.76889, Feature.10 = 95.810563, Feature.11 = 49.124086, 
Feature.12 = -21.101489, Feature.13 = -9.187984, Feature.14 = -10.53006, 
Feature.15 = -3.782506, Feature.16 = -10.805074, Feature.17 = 34.039509, 
Feature.18 = 5.64245, Feature.19 = 19.389724, Feature.20 = 16.450196, 
Class = 1L), .Names = c("Feature.1", "Feature.2", "Feature.3", 
"Feature.4", "Feature.5", "Feature.6", "Feature.7", "Feature.8", 
"Feature.9", "Feature.10", "Feature.11", "Feature.12", "Feature.13", 
"Feature.14", "Feature.15", "Feature.16", "Feature.17", "Feature.18", 
"Feature.19", "Feature.20", "Class"), class = "data.frame", row.names = c(NA, 
-1L))

另外,如何计算此模型的 R 平方或 AUC

数据集:有 10000 条记录,有 20 个特征和二进制类。

【问题讨论】:

  • 如需帮助请dput(testdata)
  • 谢谢大卫。添加 dput(testdata) 和 1 条记录。
  • 将类别标签从 (1, 0) 更改为 (yes, no) 后它正在工作
  • 改变标签向量Y后也可以工作

标签: r machine-learning


【解决方案1】:

NaiveBayes 是一个分类器,因此将 Y 转换为因子或布尔值是解决问题的正确方法。您的原始公式使用的是分类器工具,但使用的是数值,因此 R 被混淆了。

就 R 平方而言,同样,该指标仅针对回归问题而不是分类问题计算。为了评估分类问题,还有其他指标,例如 Precision 和 Recall。

有关这些指标的更多信息,请参阅维基百科链接: http://en.wikipedia.org/wiki/Binary_classification

【讨论】:

    【解决方案2】:

    改变标签向量 Y

    【讨论】:

      【解决方案3】:

      添加到您的结构中

      colClasses=c("Class"="character")
      

      【讨论】:

        猜你喜欢
        • 2014-05-08
        • 1970-01-01
        • 2013-04-13
        • 2015-09-24
        • 2013-09-09
        • 2013-04-13
        • 2016-08-16
        • 2013-10-08
        • 2016-08-21
        相关资源
        最近更新 更多