Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- V = len(dictionary)
- countC = sum(dictionary.values())
- sumOfProbs = 0
- for word in newTweet:
- if (word in dictionary):
- x = (dictionary.get(word)+1) / (countC + V)
- sumOfProbs = sumOfProbs + math.log(x)
- return sumOfProbs
- def classification(tweet):
- totalNegTweets =0
- for line in trainNegData:
- totalNegTweets += 1
- totalPosTweets =0
- for line in trainPosData:
- totalPosTweets += 1
- totalNumOfTweets = totalNegTweets + totalPosTweets
- positiveOverTotal = totalPosTweets / totalNumOfTweets
- negativeOverTotal = totalNegTweets / totalNumOfTweets
- positive = (math.log(positiveOverTotal)) +
- (calcWordProbability(tweet,posDict))
- negative = (math.log(negativeOverTotal)) +
- (calcWordProbability(tweet,negDict))
- if(positive < negative):
- prediction = 0
- else:
- prediction = 1
- return prediction
- positive = (math.log(positiveOverTotal))+(calcWordProbability(tweet,posDict))
- negative = (math.log(negativeOverTotal))+(calcWordProbability(tweet,negDict))
Add Comment
Please, Sign In to add comment