k-means中的sklearn中的dtype不匹配

Red*_*ven 6 python python-2.7 ubuntu-12.04 scikit-learn

我试图运行这个问题的第一个答案Python关联k-means集群到实例然而我收到以下错误:

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'
Run Code Online (Sandbox Code Playgroud)

当我第一次运行这个程序时,它起作用了.但后续运行失败并出现该错误.

系统规格:

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

小智 4

我在尝试对自己的数据运行 k 均值时遇到了这个问题。创建数据类型为“double”的新数组解决了我的问题。

array_double = np.array(a, dtype=np.double)
Run Code Online (Sandbox Code Playgroud)

我的数据以前存储为“float32”。