I have tried already available solution but couldn't solve this problem.
original Code:
prob = n / self.totaldocs # 0.7445791360764896
self.classpriorprob[cls] = math.log(prob)
solution: (but I prefer to take common log)
prob = n / self.totaldocs
d = Decimal(prob)
self.classpriorprob[cls] = d.ln()
As mentioned here: I tried to round the number to 3 decimal places.
prob = n / self.totaldocs
number = round(prob, 3) # 0.744
self.classpriorprob[cls] = math.log(number)
but I am still getting math domain error.
Edit: I passed the value directly i.e. math.log(0.744) and it works. It also works when I try math.log() function in python console.
Please advise.
Specs:
python 3.6.3
pycharm