Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. def predict(self, X):
  2. # This is just a place holder so that the code still runs.
  3. # Your code goes here.
  4.  
  5. for row in range(0, len(X)):
  6. probTrue = long(1)
  7. probFalse = long(1)
  8. probE = 0
  9. for column in range(0, len(X[0])):
  10. if(X[row][column] == 1):
  11. probTrue *= np.log((float(self.attributeCountTrue[column]) + 1) / (float(self.resultTrueCount) + 2))
  12. probFalse *= np.log((float(self.attributeCountTrue[column]) + 1) / (float(self.resultFalseCount) + 2))
  13. if (X[row][column] == 0):
  14. probTrue *= np.log(float(self.attributeCountFalse[column]) + 0) / (float(self.resultTrueCount) + 2)
  15. probFalse *= np.log((float(self.attributeCountFalse[column]) + 0) / (float(self.resultFalseCount) + 2))
  16. #print "ProbTrue = ", probTrue
  17.  
  18. probTrue *= (self.resultTrueCount/(np.log(self.resultTrueCount+self.resultFalseCount)))
  19. probFalse *= (self.resultFalseCount / (np.log(self.resultTrueCount + self.resultFalseCount)))
  20.  
  21. probE = probTrue + probFalse
  22. #probTrue /= probE
  23. #probFalse /= probE
  24. print "ProbTrue = ", probTrue
  25. print "ProbFalse = ", probFalse
  26. #print "ProbTrue = ", probTrue
  27. #print "ProbFalse = ", probFalse
  28. print ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement