2014-01-19 64 views
6

我試圖第一個答案運行到這個問題Python Relating k-means cluster to instance但是我收到以下錯誤:D型不匹配的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' 

當我運行這個程序中的第一次,它的工作。但隨後的運行失敗並出現該錯誤。

系統規格:

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

什麼是你的輸入矩陣的'dtype'? –

回答

1

我跑這個問題,而試圖在我自己的數據運行K-均值。創建一個數據類型爲'double'的新數組解決了我的問題。

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

我的數據以前存儲爲'float32'。