0

I am trying to run a simple naive bayes model (trying to redo what I have seen the datacamp course).

I am using the R naivebayes package.

The training dataset is where9am which looks like this:

where9am

My first problem is the following... when I have several predictions in a dataframe thursday9am...

thursday9am

... and I use the following code:

locmodel <- naive_bayes(location ~ daytype, data = where9am)
my_pred <- predict(locmodel, thursday9am)

I get a series of <NA> while it works well with the correct prediction if the thursday9am dataframe only contains a single observation.

output with multiple rows to predict

output with a single prediction

The second problem is the following: when I use the following code to get the associated probabilities...

locmodel <- naive_bayes(location ~ daytype, data = where9am, type = c("class", "prob"))
predict(locmodel, thursday9am , type = "prob")

... even if I have only one observation in thursday9am, I get a series of <NaN>.

output with type = "prob"

I am not sure what I am doing wrong.

Community
  • 1
  • 1
lbo34
  • 41
  • 1
  • Please [see here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to post an R question that folks can answer. We don't have your data, so we can't recreate the situation. Please also post all code and console output as formatted text, not images. – camille May 26 '18 at 18:45
  • I ran exactly the code that you provided and _did not_ get the NAS. I got the expected prediction of `office`. You should check `where9am` and `thursday9am` to make sure that they contain what you expect. – G5W May 26 '18 at 18:54

0 Answers0