dtype mismatch in sklearn on k-means

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I am attempting to run the first answer to this question Python Relating k-means cluster to instance however I am getting the following error:

Traceback (most recent call last):   File "test.py", line 16, in <module>     model = sklearn.cluster.k_means(a, clust_centers)    File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.14.1-py2.7-linux-i686.egg/sklearn/cluster/k_means_.py", line 267, in k_means     x_squared_norms=x_squared_norms, random_state=random_state)   File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.14.1-py2.7-linux-i686.egg/sklearn/cluster/k_means_.py", line 386, in _kmeans_single     centers = _k_means._centers_dense(X, labels, n_clusters, distances)   File "_k_means.pyx", line 280, in sklearn.cluster._k_means._centers_dense (sklearn/cluster/_k_means.c:4268) ValueError: Buffer dtype mismatch, expected 'DOUBLE' but got 'float' 

When I ran this program the first time, it worked. But subsequent runs fail with that error.

Systems specs:

Python 2.7.3 (default, Sep 26 2013, 20:08:41) [GCC 4.6.3] on linux2

numpy.__version__ '1.8.0'

sklearn.__version__ '0.14.1'

ubuntu 12.04

回答1:

I ran in to this issue while trying to run k-means on my own data. Creating a new array with data type 'double' solved my issue.

array_double = np.array(a, dtype=np.double) 

My data was previously stored as 'float32'.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!