在Python的小浮动趋于零 [英] In Python small floats tending to zero

查看:191
本文介绍了在Python的小浮动趋于零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Python编程的贝叶斯分类器,问题是,当我乘以特征概率,我得到非常小的浮动值,如2.5e-320或类似的东西,突然它变成0.0。 0.0对我来说显然是没有用的,因为我必须根据哪个类返回MAX值(更大的值)来找到最佳类。



什么是处理这个最好的办法?我想到找到数字的指数部分(-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆