简体   繁体   中英

Using naive bayes to predict new values

I have a dataframe that looks like this

weather <- c("good", "good", "good", "bad", "bad", "good")
temp <- c("high", "low", "low", "high", "low", "low")
golf <- c("yes", "no", "yes", "no", "yes" , "no")
df <- data.frame(weather, temp, golf)

What I would like to do now is using the naive bayes method to get probability of this new dataset

df_new <- data.frame(weather = "good", temp = "low")

Therefore I try

library(e1071)
model <- naiveBayes(golf ~.,data=df)
predict(model, df_new)

But this gives me:

NO

Any idea how i can turn this into a probability?

probabilities are returned if you use type = "raw"

predict(model, df_new, type = "raw")
no yes
[1,] 0.5 0.5

predict(model, df_new, type = "class")
[1] no
Levels: no yes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM