raise LinAlgError(“SVD did not converge”) LinAlgError: SVD did not converge in matplotlib pca determination

前端 未结 9 1219
后悔当初
后悔当初 2021-02-05 02:10

code :

import numpy
from matplotlib.mlab import PCA
file_name = \"store1_pca_matrix.txt\"
ori_data = numpy.loadtxt(file_name,dtype=\'float\', comments=\'#\', de         


        
相关标签:
9条回答
  • 2021-02-05 03:02

    I know this post is old, but in case someone else encounters the same problem. @jseabold was right when he said that the problem is nan or inf and the op was probably right when he said that the data did not have nan's or inf. However, if one of the columns in ori_data has always the same value, the data will get Nans, since the implementation of PCA in mlab normalizes the input data by doing

    ori_data = (ori_data - mean(ori_data)) / std(ori_data).
    

    The solution is to do:

    result = PCA(ori_data, standardize=False)
    

    In this way, only the mean will be subtracted without dividing by the standard deviation.

    0 讨论(0)
  • 2021-02-05 03:03

    I am using numpy 1.11.0. If the matrix has more than 1 eigvalues equal to 0, then 'SVD did not converge' is raised.

    0 讨论(0)
  • 2021-02-05 03:04

    If there are no inf or NaN values, possibly that is a memory issue. Please try in a machine with higher RAM.

    0 讨论(0)
提交回复
热议问题