简体   繁体   English

scipy.cluster.vq.kmeans2中的“矩阵不是肯定的”错误

[英]“Matrix is not positive definite” error in scipy.cluster.vq.kmeans2

I am trying to perform kmeans clustering over 128-dimensional points (descriptors of interest points in an image). 我试图在128维点(图像中的兴趣点的描述符)上执行kmeans聚类。 When I use scipy.cluster.vq.kmeans2 function, I sometimes get the following error: 当我使用scipy.cluster.vq.kmeans2函数时,我有时会收到以下错误:

  File "main.py", line 21, in level_routine
current.centroids, current.labels = cluster.vq.kmeans2( current.descriptors, k)
  File "/usr/lib/python2.7/dist-packages/scipy/cluster/vq.py", line 706, in kmeans2
    clusters = init(data, k)
  File "/usr/lib/python2.7/dist-packages/scipy/cluster/vq.py", line 593, in _krandinit
    return init_rankn(data)
  File "/usr/lib/python2.7/dist-packages/scipy/cluster/vq.py", line 586, in init_rankn
    x = np.dot(x, np.linalg.cholesky(cov).T) + mu
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 603, in cholesky
    return wrap(gufunc(a, signature=signature, extobj=extobj).astype(result_t))
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 93, in _raise_linalgerror_nonposdef
    raise LinAlgError("Matrix is not positive definite")
numpy.linalg.linalg.LinAlgError: Matrix is not positive definite

I know that this has something to do with the random initialization because on the same data and for the same k , I sometimes do not get this error. 我知道这与随机初始化有关,因为在相同的data和相同的k ,我有时不会得到这个错误。

My data is a numpy matrix with 128 columns and variable number of rows. 我的data是一个numpy矩阵,有128列和可变行数。 I am not constructing the co-variance matrix, and hence do not have control over the same. 我没有构建协方差矩阵,因此无法控制它。 Is there a way of getting rid of this error. 有没有办法摆脱这个错误。

尝试将minit参数更改为'points':

kmeans2(obs,k,minit='points')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM