Я пытаюсь классифицировать невидимые твиты, используя полиномиальную наивную модель Байеса.Я получаю ошибку и не могу понять, как ее исправить.ValueError: ошибка математического домена.Ошибка возникает при использовании функции math.log.Любые идеи, как это исправить?
def calcWordProbability(newTweet, dictionary):
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))