在Python的小浮动趋于零 [英] In Python small floats tending to zero
问题描述
什么是处理这个最好的办法?我想到找到数字的指数部分(-320),如果它太低,乘以1e20或像这样的一些值。但是,也许有更好的办法?
您所描述的是朴素贝叶斯分类器的标准问题。你可以搜索下溢与找到答案。或在此处。
简短的回答是用<对数来表达所有的标准。因此,不是乘以概率,而是求和它们的对数。
您可能还想看其他算法以及分类。
I have a Bayesian Classifier programmed in Python, the problem is that when I multiply the features probabilities I get VERY small float values like 2.5e-320 or something like that, and suddenly it turns into 0.0. The 0.0 is obviously of no use to me since I must find the "best" class based on which class returns the MAX value (greater value).
What would be the best way to deal with this? I thought about finding the exponential portion of the number (-320) and, if it goes too low, multiplying the value by 1e20 or some value like that. But maybe there is a better way?
What you describe is a standard problem with the naive Bayes classifier. You can search for underflow with that to find the answer. or see here.
The short answer is it is standard to express all that in terms of logarithms. So rather than multiplying probabilities, you sum their logarithms.
You might want to look at other algorithms as well for classification.
这篇关于在Python的小浮动趋于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!