Guest User

Untitled

a guest
Dec 13th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. V = len(dictionary)
  2. countC = sum(dictionary.values())
  3.  
  4. sumOfProbs = 0
  5.  
  6. for word in newTweet:
  7. if (word in dictionary):
  8. x = (dictionary.get(word)+1) / (countC + V)
  9.  
  10. sumOfProbs = sumOfProbs + math.log(x)
  11.  
  12. return sumOfProbs
  13.  
  14. def classification(tweet):
  15.  
  16. totalNegTweets =0
  17. for line in trainNegData:
  18. totalNegTweets += 1
  19.  
  20. totalPosTweets =0
  21. for line in trainPosData:
  22. totalPosTweets += 1
  23.  
  24.  
  25. totalNumOfTweets = totalNegTweets + totalPosTweets
  26. positiveOverTotal = totalPosTweets / totalNumOfTweets
  27. negativeOverTotal = totalNegTweets / totalNumOfTweets
  28.  
  29. positive = (math.log(positiveOverTotal)) +
  30. (calcWordProbability(tweet,posDict))
  31. negative = (math.log(negativeOverTotal)) +
  32. (calcWordProbability(tweet,negDict))
  33.  
  34. if(positive < negative):
  35. prediction = 0
  36. else:
  37. prediction = 1
  38.  
  39. return prediction
  40.  
  41. positive = (math.log(positiveOverTotal))+(calcWordProbability(tweet,posDict))
  42. negative = (math.log(negativeOverTotal))+(calcWordProbability(tweet,negDict))
Add Comment
Please, Sign In to add comment