From 1caffe80a93dd0d6fe8880c1f6b9817f7d742d59 Mon Sep 17 00:00:00 2001
From: Michel Vincent <vm.michel@gmail.com>
Date: Mon, 26 Apr 2010 07:21:58 +0000
Subject: [PATCH] Fix a bug in the computation of the log lokelihood

git-svn-id: https://scikit-learn.svn.sourceforge.net/svnroot/scikit-learn/trunk@707 22fbfee3-77ab-4535-9bad-27d1bd3bc7d8
---
 scikits/learn/naive_bayes.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/scikits/learn/naive_bayes.py b/scikits/learn/naive_bayes.py
index a6c34574ee..887e158bef 100644
--- a/scikits/learn/naive_bayes.py
+++ b/scikits/learn/naive_bayes.py
@@ -75,11 +75,10 @@ class GNB(object):
         joint_log_likelihood = []
         for i in range(np.size(self.unique_y)):
             jointi = np.log(self.proba_y[i])
-            n_ij = np.sum(-0.5 * np.log(np.pi * self.sigma[i,:]))
-            n_ij = n_ij * np.ones(np.size(X, 0))
-            n_ij -= np.sum((X - self.theta[i,:])**2, 1)
-            n_ij += np.sum(2 * self.sigma[i,:]) * np.ones(np.size(X, 0))
-            joint_log_likelihood.append(jointi + n_ij)
+            n_ij = - 0.5 * np.sum(np.log(np.pi*self.sigma[i,:]))
+            n_ij -= 0.5 * np.sum( ((X - self.theta[i,:])**2) /\
+                                    (self.sigma[i,:]),1)
+            joint_log_likelihood.append(jointi+n_ij)
         joint_log_likelihood = np.array(joint_log_likelihood).T
         proba = np.exp(joint_log_likelihood)
         proba = proba / np.sum(proba,1)[:,np.newaxis]
-- 
GitLab