我正在尝试预测是否播放给定的新数据:
m <- NaiveBayes(as.factor(play)~ ., data=train)
weather Temp humidity wind play
fine hot high none no
fine hot high few no
cloud hot high none yes
rain warm high none yes
rain cold medium none yes
rain cold medium few no
cloud cold medium few yes
fine warm high none no
fine cold medium none yes
我用它来创建新的测试实例
`> wind <- factor("few",levels(train$wind))
> Temp <- factor("cold",levels(train$Temp))
> humidity <- factor("high",levels(train$humidity))
> weather<- factor("cloud",levels(train$weather))
test <- data.frame(weather,Temp,humidity,wind)
predict(m,newdata=test)`
这是输出
$class
[1] yes
Levels: no yes
$posterior
no yes
[1,] 0.004836495 0.9951635
我也试过
m <- NaiveBayes(as.factor(train)~ ., data=train.play)
但返回相同的概率