r - 使用 R 对朴素贝叶斯进行 10 倍交叉验证时出现回归错误的模型类型错误

标签 r machine-learning

我正在对 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 个特征和 Binary 类。

最佳答案

NaiveBayes 是一个分类器,因此将 Y 转换为因子或 bool 值是解决该问题的正确方法。您最初的公式使用了分类器工具,但使用了数值,因此 R 很困惑。

就 R 方而言,该指标仅针对回归问题而不是分类问题计算。为了评估分类问题,还有其他指标,例如精度和召回率。

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

关于r - 使用 R 对朴素贝叶斯进行 10 倍交叉验证时出现回归错误的模型类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23357855/

相关文章:

machine-learning - SMOTE后产生的结果可靠吗?

python - 在 scikit-learn 中训练神经网络计算 'XOR'

r - ggplot2scale_fill_gradient2不显示中间颜色

r - 将图像或pdf插入R中的word文档

r - 如何从变化的数据帧创建查找表?

python - 如何将 2d numpy 数组转换为最大值的二进制指示矩阵

python - 如何使用 optuna trial 在 sklearn MLPRegressor 中设置 hidden_​​layer_sizes

Java-R 集成?

r - 将信息打印到shiny-server日志中

R:GLM 中饱和模型的对数似然