sklearn 错误 ValueError:输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值 [英] sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype('float64')

查看:108
本文介绍了sklearn 错误 ValueError:输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sklearn 并且在亲和传播方面遇到问题.我已经建立了一个输入矩阵,但我不断收到以下错误.

I am using sklearn and having a problem with the affinity propagation. I have built an input matrix and I keep getting the following error.

ValueError: Input contains NaN, infinity or a value too large for dtype('float64').

我跑了

np.isnan(mat.any()) #and gets False
np.isfinite(mat.all()) #and gets True

我尝试使用

mat[np.isfinite(mat) == True] = 0

删除无限值,但这也不起作用.我该怎么做才能摆脱矩阵中的无限值,以便我可以使用亲和传播算法?

to remove the infinite values but this did not work either. What can I do to get rid of the infinite values in my matrix, so that I can use the affinity propagation algorithm?

我正在使用 anaconda 和 python 2.7.9.

I am using anaconda and python 2.7.9.

推荐答案

这可能发生在 scikit 内部,这取决于您在做什么.我建议您阅读有关您正在使用的功能的文档.您可能正在使用一种取决于例如您的矩阵为正定且不满足该标准.

This might happen inside scikit, and it depends on what you're doing. I recommend reading the documentation for the functions you're using. You might be using one which depends e.g. on your matrix being positive definite and not fulfilling that criteria.

编辑:我怎么能错过:

np.isnan(mat.any()) #and gets False
np.isfinite(mat.all()) #and gets True

显然是错误的.正确的应该是:

is obviously wrong. Right would be:

np.any(np.isnan(mat))

np.all(np.isfinite(mat))

您想检查是否有任何元素为 NaN,而不是 any 函数的返回值是否为数字...

You want to check wheter any of the element is NaN, and not whether the return value of the any function is a number...

这篇关于sklearn 错误 ValueError:输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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