# Multinomial Naive bayes giving wrong result

from sklearn.naive_bayes import GaussianNB,MultinomialNB
xx = [[1],[1],[1],[2],[2],[3]]
yy = [1,1,1,0,0,0]
clf = GaussianNB()
# clf = MultinomialNB()
clf.fit(xx,yy)
clf.predict(xx)


The expected result is [1,1,1,0,0,0] but code output is [0,0,0,0,0,0].

• Check the regularization parameter--that's often the problem with questions like these. If it's too high, this can happen. Aug 28, 2019 at 6:51
• @SheridanGrant you mean alpha parameter for Laplace smoothing right. the default value for it is 1. Aug 28, 2019 at 7:05

There is only one feature for xx.
For a MultinomialNB, the modelled probability of the feature per class $$p(x_i|y)$$ is always the same ($$\frac{3}{3}=1$$ for class $$1$$ and $$\frac{7}{7}=1$$ for class $$0$$). The prediction is therefore the class prior $$p(y_i)$$ which is also the same here ($$p(0) = 0.5$$ and $$p(1)=0.5$$) so by default class $$0$$. Having one feature does not really makes sense because it gives no information to the model on what gives discriminative power toward the classes.
For a GaussianNB this is different because the modelled probability is given by $$P(x_i \mid y) = \frac{1}{\sqrt{2\pi\sigma^2_y}} \exp\left(-\frac{(x_i - \mu_y)^2}{2\sigma^2_y}\right)$$ so the mean and variance per class of the single feature give sufficient information.