问题描述
我正在尝试运行这个问题的第一个答案 Python 相关 k-means cluster to instance 但是我收到以下错误:
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.
系统规格:
Python 2.7.3(默认,2013 年 9 月 26 日,20:08:41)[GCC 4.6.3] 在 linux2 上
numpy.__version__'1.8.0'
sklearn.__version__'0.14.1'
ubuntu 12.04
推荐答案
我在尝试对自己的数据运行 k-means 时遇到了这个问题.创建一个数据类型为double"的新数组解决了我的问题.
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)
我的数据以前存储为float32".
My data was previously stored as 'float32'.
这篇关于k-means 上 sklearn 中的 dtype 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!