I am new to R and start to play around naive bayes algorithm. But I run into a problem which I could not figure out why: for the following sample data, the predict function (using a naive bayes model) always gives me zero length. Do you have any hints? Thanks Here is the code:> titanic_smallsurvived pclass 1 0 3 2 1 1 3 1 3 4 1 1 5 0 3 6 0 3> model <- naiveBayes(survived~., data=titanic_small) > prediction <- predict(model, titanic_small[,-1]) > length(prediction)[1] 0 [[alternative HTML version deleted]]
If you look at the help for predict.naiveBayes, you can see that newdata is supposed to be a data.frame. However, you are providing newdata as a vector, titanic_small[,-1]. Try using titanic_small[,-1, drop=FALSE] instead. Jean On Tue, Mar 12, 2013 at 11:35 PM, S. Zhou <myxjtu@yahoo.com> wrote:> titanic_small[,-1][[alternative HTML version deleted]]