【问题标题】:ROC curve errorROC曲线误差
【发布时间】:2018-04-25 16:19:35
【问题描述】:

我有这样的数据集

train <- sample(1:nrow(df), nrow(df)*0.80)
train <- df[train, ]
test <- df[-train, ]


NaiveBayes1 <-naiveBayes(purchased ~ .,data=train)
pre1 <- predict(NaiveBayes1,test,probability = TRUE)

library(pROC)
roc1 <- roc(test$purchased, pre1$posterior[,1])

我得到这个错误:

pre1$posterior 中的错误:$ 运算符对原子向量无效

我已经在课堂上使用 LDA 完成了,它有效,但对于 naivebays,它不起作用。任何帮助将不胜感激。

【问题讨论】:

    标签: r naivebayes roc


    【解决方案1】:

    将您的最后两行更改为:

    pre1 <- predict(NaiveBayes1, test, probability = TRUE)
    roc1 <- roc(test$purchased, pre1$posterior[,1])
    

    收件人:

    pre1 <- predict(NaiveBayes1, test, type = "raw")
    roc1 <- roc(test$purchased, pre1[,1])
    

    【讨论】:

    • pre1
    • 抱歉,应该是type = "raw" 而不是type = raw。我已经更新了我的答案,希望这能解决您的问题
    猜你喜欢
    • 2016-01-22
    • 2018-01-03
    • 2019-12-26
    • 2014-11-18
    • 2019-02-27
    • 2014-07-20
    • 2012-05-02
    • 2019-02-09
    • 1970-01-01
    相关资源
    最近更新 更多