2016-07-23 30 views
-2

我在Python中使用Spectral Clustering Library,相似矩陣是它的主要參數。我矩陣是這樣的:Sklearn譜在fit_predict中的聚類錯誤:k必須在1和矩形輸入矩陣的順序之間

[[ 1.   0.85018854 0.85091491 0.85717652] 
[ 0.85018854 1.   0.99720197 0.99732831] 
[ 0.85091491 0.99720197 1.   0.9972462 ] 
[ 0.85717652 0.99732831 0.9972462 1.  ]] 

而且我的代碼類似的文件樣本:

cl = SpectralClustering(n_clusters=4,affinity='precomputed') 
y = cl.fit_predict(matrix) 

但出現下列錯誤:

Traceback (most recent call last): 
    File "/home/mahmood/PycharmProjects/sentence2vec/graphClustering.py", line 22, in <module> 
    y = cl.fit_predict(matrix) 
    File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/base.py", line 371, in fit_predict 
    self.fit(X) 
    File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/cluster/spectral.py", line 454, in fit 
    assign_labels=self.assign_labels) 
    File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/cluster/spectral.py", line 258, in spectral_clustering 
    eigen_tol=eigen_tol, drop_first=False) 
    File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/manifold/spectral_embedding_.py", line 254, in spectral_embedding 
    tol=eigen_tol) 
    File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 1507, in eigsh 
    raise ValueError("k must be between 1 and the order of the " 
ValueError: k must be between 1 and the order of the square input matrix. 

我不知道,我需要知道什麼是問題,也許是解決方案。

回答

1

您有4個數據點。

您請求4個羣集。

你預計會發生什麼?

只有微不足道的解決方案(每個點都不同),因此譜聚類拒絕運行。對於明智的解決方案,顯然,羣集的數量必須至少爲2,而最多爲n-1。

+0

感謝您的正確迴應 –

相關問題