-1

I have dataset like this

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])

And I get this error:

Error in pre1$posterior : $ operator is invalid for atomic vectors

I have done in the class using LDA and it worked but for naivebays, it doesn't work. Any help will be appreciated.

joerna
  • 435
  • 1
  • 6
  • 13

1 Answers1

1

Change your last two lines from:

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

To:

pre1 <- predict(NaiveBayes1, test, type = "raw")
roc1 <- roc(test$purchased, pre1[,1])
jruf003
  • 980
  • 5
  • 19
  • pre1 <- predict(NaiveBayes1,test,type = raw) Error in match.arg(type) : 'arg' must be NULL or a character vector .....this gave me new error... – joerna Nov 13 '17 at 05:17
  • Sorry, it should have been `type = "raw"` not `type = raw`. I've updated my answer and hopefully this should fix your problem – jruf003 Nov 13 '17 at 05:25