NaiveBayes in R Cannot Predict - factor(0) Levels:

允我心安 提交于 2019-11-30 09:13:23

Problem isn't in the predict() function but in your model definition.

Help file of naiveBayes() says:

Computes the conditional a-posterior probabilities of a categorical class variable 
given independent predictor variables using the Bayes rule.

So y values should be categorical but in your case they are numeric.

Solution is to convert flu to factor.

model <- naiveBayes(as.factor(flu)~., data=data.flu)
predict(model, patient)
[1] 1
Levels: 0 1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!