cannot use sklearn.naive_bayes MultinomialNB to predict from one attribute I tried to create a simple example for Naive Bayes by learning from one attribute.  It seems like I cannot use sklearn.naive_bayes.MultinomialNB to predict from one attribute.  This is because the predict_proba is the same for every input.

Here is the code:

import numpy as np
X = np.array([1, 1, 1, 0, 0, 1, 1])
X = X.reshape(-1,1)
y = np.array([0, 0, 0, 0, 1, 1, 1])

from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()
clf.fit(X, y)

print(clf.predict(X))
print(clf.predict_proba(X))


and its result.

[0 0 0 0 0 0 0]
[[0.57142857 0.42857143]
 [0.57142857 0.42857143]
 [0.57142857 0.42857143]
 [0.57142857 0.42857143]
 [0.57142857 0.42857143]
 [0.57142857 0.42857143]
 [0.57142857 0.42857143]]
If your problem is shaped as you stated, you might need to reconsider your Naive Bayes model. MultinomialNB does not seem to be appropriate for your case. You can rather use the Naive Bayes classifier that uses the gaussian distribution.

from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
gnb.fit(X, y)
print(gnb.predict(X))
print(gnb.predict_proba(X))