Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f228fdb

Browse files
committed
Fix bug in MultinomialNB: output transposed
Quick fix: .T before return. Needs a proper fix.
1 parent 1af80ea commit f228fdb

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

scikits/learn/naive_bayes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,4 @@ def predict_log_proba(self, X):
408408
jll = self._joint_log_likelihood(X)
409409
# normalize by P(x) = P(f_1, ..., f_n)
410410
log_prob_x = np.logaddexp.reduce(jll[:, np.newaxis])
411-
return jll - log_prob_x
411+
return (jll - log_prob_x).T

scikits/learn/tests/test_naive_bayes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_mnnb_predict_proba():
104104

105105
clf = naive_bayes.MultinomialNB().fit([[0,1], [0,1], [1,0]], [0,0,1])
106106
assert clf.predict([0,1]) == 0
107+
assert clf.predict_proba([0,1]).shape == (1,2)
107108
assert np.sum(clf.predict_proba([0,1])) == 1
108109
assert np.sum(clf.predict_proba([1,0])) == 1
109110
assert np.sum(np.exp(clf.class_log_prior_)) == 1

0 commit comments

Comments
 (0)