I am trying to execute kmeans clusters on 128-dimensional points (descriptors of points of interest in the image). When I use a function scipy.cluster.vq.kmeans2, I sometimes get the following error:
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 random initialization, because in the same dataand for the same k, I sometimes do not get this error.
My datais a numeric matrix with 128 columns and a variable number of rows. I do not build a matrix of joint dispersion and, therefore, do not control it. Is there any way to get rid of this error.
source
share