pythonmatplotlibpca

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


Code:

import numpy
from matplotlib.mlab import PCA
file_name = "store1_pca_matrix.txt"
ori_data = numpy.loadtxt(file_name,dtype='float', comments='#', delimiter=None,
            converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0)
result = PCA(ori_data)

Though my input matrix is devoid of nan and inf, I do get the error below:

    raise LinAlgError("SVD did not converge")
LinAlgError: SVD did not converge

What's the problem?


Solution

  • This can happen when there are inf or nan values in the data.

    Use this to remove nan values:

    ori_data.dropna(inplace=True)