使用朴素贝叶斯预测新值
Using naive bayes to predict new values
我有一个看起来像这样的数据框
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)
我现在想做的是使用朴素贝叶斯方法得到这个新数据集的概率
df_new <- data.frame(weather = "good", temp = "low")
所以我试试
library(e1071)
model <- naiveBayes(golf ~.,data=df)
predict(model, df_new)
但这给了我:
NO
知道如何将其转化为概率吗?
如果您使用 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
我有一个看起来像这样的数据框
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)
我现在想做的是使用朴素贝叶斯方法得到这个新数据集的概率
df_new <- data.frame(weather = "good", temp = "low")
所以我试试
library(e1071)
model <- naiveBayes(golf ~.,data=df)
predict(model, df_new)
但这给了我:
NO
知道如何将其转化为概率吗?
如果您使用 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