我想在矩阵上运行pca,但只得到一个numpy.linalg.linalg.LinAlgError。 我附上了矩阵和我的代码。
在此处获取矩阵:http://workupload.com/file/YvSVhGJA
import numpy as np
from sklearn.decomposition import PCA
matrix = np.load("matrix.npy")
transformed = PCA(n_components=3).fit_transform(matrix)
这是完整的堆栈跟踪,但我认为你可以重现它。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/anaconda/lib/python2.7/site-packages/sklearn/decomposition/pca.py", line 242, in fit_transform
U, S, V = self._fit(X)
File "/home/user/anaconda/lib/python2.7/site-packages/sklearn/decomposition/pca.py", line 275, in _fit
U, S, V = linalg.svd(X, full_matrices=False)
File "/home/user/anaconda/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 109, in svd
raise LinAlgError("SVD did not converge")
numpy.linalg.linalg.LinAlgError: SVD did not converge
感谢任何帮助。
PS:
np.__version__
'1.9.2'
sklearn.__version__
'0.15.2'
PPS:我正在运行Linux
答案 0 :(得分:0)
它适用于Mac,我觉得这对你没什么帮助
然后尝试X[:,:100]
:1000?
有LAPACK tests for SVD;他们看起来令人生畏 A&#34;告诉我关于我的LAPACK安装的所有信息&#34;命令会很有用, 但我不能随便看到。
from __future__ import division
import platform
import sys
import numpy as np
from numpy.distutils.system_info import get_info
np.set_printoptions( threshold=100, edgeitems=10, linewidth=80,
formatter = dict( float = lambda x: "%.2g" % x )) # float arrays %.2g
def versions():
print "versions: numpy %s python %s " % (
np.__version__, sys.version.split()[0] )
if platform.system() == "Darwin":
print "mac %s" % platform.mac_ver()[0]
else:
print platform.platform( terse=1 ) # ?
for info in "blas_opt lapack_opt " .split():
print "%s: %s" % (info, get_info( info, 0 ))
print ""
versions()
#...............................................................................
X = np.load( "matrix.npy" )
print "X:", X.shape, np.percentile( X, q=[0,25,50,75,100] )
U, sing, Vt = np.linalg.svd( X, full_matrices=False )
print "np.linalg.svd: X %s -> U %s sing %s Vt %s" % (
X.shape, U.shape, sing.shape, Vt.shape )
print "svd sing:", sing
versions: numpy 1.9.2 python 2.7.6
mac 10.8.3
blas_opt: {'extra_link_args': ['-Wl,-framework', '-Wl,Accelerate'], 'extra_compile_args': ['-msse3', '-DAPPLE_ACCELERATE_SGEMV_PATCH', '-I/System/Library/Frameworks/vecLib.framework/Headers'], 'define_macros': [('NO_ATLAS_INFO', 3)]}
lapack_opt: {'extra_link_args': ['-Wl,-framework', '-Wl,Accelerate'], 'extra_compile_args': ['-msse3', '-DAPPLE_ACCELERATE_SGEMV_PATCH'], 'define_macros': [('NO_ATLAS_INFO', 3)]}
X: (384, 5000) [-4.4e+02 -20 -0.27 17 4.5e+02]
np.linalg.svd: X (384, 5000) -> U (384, 384) sing (384,) Vt (384, 5000)
svd sing: [5e+04 2.3e+04 2.1e+04 1.3e+04 1.2e+04 1.1e+04 1.1e+04 4.3e+03 3.3e+03 1.8e+03
..., 0.00014 0.00014 0.00013 0.00013 0.00011 5.3e-12 5.3e-12 5.1e-16 1.3e-16
3.3e-17]