R语言 e1071包 调用naiveBayes函数,预测时没有结果。

模型训练过程,正常,结果如下:
naiveBayesClassifier

Naive Bayes Classifier for Discrete Predictors

Call:
naiveBayes.default(x = X, y = Y, laplace = laplace)

A-priori probabilities:
Y
-1979 +1990 1980-1989
0.1153125 0.3043750 0.5803125

Conditional probabilities:
count
Y [,1] [,2]
-1979 76.46070 27.52961
+1990 71.94867 29.80863
1980-1989 75.12601 29.20054

       avgRetweetCount

Y [,1] [,2]
-1979 0.3666456 1.2544417
+1990 0.2539568 0.6264289
1980-1989 0.3489661 1.3528286

       avgReviewCount

Y [,1] [,2]
-1979 0.3447768 0.7766726
+1990 0.6835772 1.1494203
1980-1989 0.4447086 0.8397381

       sourceCount

Y [,1] [,2]
-1979 15.98103 8.710137
+1990 14.77002 8.065539
1980-1989 15.46527 8.315700

但是在预测时,预测代码:prediction <- predict(naiveBayesClassifier, naiveBayesData[12, 2:5])

返回值:
prediction
factor(0)
Levels:

这是什么问题,求解答!!

http://www.biostatistic.net/thread-35493-1-1.html

我也遇到了并且解决了。解决方法是需要把目标变量设置为因子型的。