首页 > 其他 > 详细

使用sklearn的pca模块fit数据报错“ValueError: array must not contain infs or NaNs”

时间:2021-04-03 21:02:32      阅读:107      评论:0      收藏:0      [点我收藏+]

 

 

使用sklearn的pca模块fit数据报错“ValueError: array must not contain infs or NaNs”:

Traceback (most recent call last):
  File "xxx.py", line 57, in <module>
    pca.fit(train_X)
  File "C:\Users\xyj\AppData\Roaming\Python\Python37\site-packages\sklearn\decomposition\_pca.py", line 351, in fit
    self._fit(X)
  File "C:\Users\xyj\AppData\Roaming\Python\Python37\site-packages\sklearn\decomposition\_pca.py", line 425, in _fit
    return self._fit_truncated(X, n_components, self._fit_svd_solver)
  File "C:\Users\xyj\AppData\Roaming\Python\Python37\site-packages\sklearn\decomposition\_pca.py", line 545, in _fit_truncated
    random_state=random_state)
  File "C:\Users\xyj\AppData\Roaming\Python\Python37\site-packages\sklearn\utils\validation.py", line 73, in inner_f
    return f(**kwargs)
  File "C:\Users\xyj\AppData\Roaming\Python\Python37\site-packages\sklearn\utils\extmath.py", line 358, in randomized_svd
    Uhat, s, V = linalg.svd(B, full_matrices=False)
  File "X:\anaconda\lib\site-packages\scipy\linalg\decomp_svd.py", line 109, in svd
    a1 = _asarray_validated(a, check_finite=check_finite)
  File "X:\anaconda\lib\site-packages\scipy\_lib\_util.py", line 239, in _asarray_validated
    a = toarray(a)
  File "C:\Users\xyj\AppData\Roaming\Python\Python37\site-packages\numpy\lib\function_base.py", line 499, in asarray_chkfinite
    "array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs

  参考github对应库的issues进行解决,https://github.com/scikit-learn/scikit-learn/issues/18138,第一次fit在try里面运行,第二次就成功fit。:

try:
    pca.fit(train_X)
except:
    pca.fit(train_X)

至于原因。。。没时间看了

使用sklearn的pca模块fit数据报错“ValueError: array must not contain infs or NaNs”

原文:https://www.cnblogs.com/youmuchen/p/14613746.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!