The problem is that the dependent variable is expected to be a factor. Instead of using a matrix to store data, I will use a data frame (below df), which can store several types of variables (for example, number and factors). I store in df the coefficient Y and the number X and run the model ...
df<-data.frame(Y=factor(c(0,1,1)),X=c(3,1,3)) model<-naiveBayes(Y~X,df) predict(model,df)
Alternatively, to show that this is a factor that fixed the problem (i.e. not using a formula) ...
model<-naiveBayes(df[,2],df[,1]) predict(model,df)
Still working.
source share