Python Sklearn fit_predict中的谱聚类误差:k必须介于1和平方输入矩阵的阶数之间

Python Sklearn fit_predict中的谱聚类误差:k必须介于1和平方输入矩阵的阶数之间,python,numpy,matrix,scikit-learn,cluster-analysis,Python,Numpy,Matrix,Scikit Learn,Cluster Analysis,我在Python中使用了相似矩阵,它的主要参数是相似矩阵。我的矩阵看起来像: [[ 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. ]] 我的代码与

我在Python中使用了相似矩阵,它的主要参数是相似矩阵。我的矩阵看起来像:

[[ 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.
回溯(最近一次呼叫最后一次):
文件“/home/mahmood/PycharmProjects/sentence2vec/graphClustering.py”,第22行,在
y=cl.fit_预测(矩阵)
文件“/usr/local/lib/python2.7/dist packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/base.py”,第371行,在fit_中
自我适应(X)
文件“/usr/local/lib/python2.7/dist packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/cluster/spectrum.py”,第454行
分配\u标签=自身。分配\u标签)
文件“/usr/local/lib/python2.7/dist packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/cluster/spectrum.py”,第258行,spectrum_clustering
本征值=本征值,先下降值=假)
文件“/usr/local/lib/python2.7/dist packages/scikit_-learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/manifold/spectrum_-embedding_u.py”,第254行,spectrum_-embedding中
tol=本征值(tol)
文件“/usr/lib/python2.7/dist packages/scipy/sparse/linalg/eigen/arpack/arpack.py”,第1507行,在eigsh中
raise VALUE ERROR(“k必须介于1和顺序之间”
ValueError:k必须介于1和方形输入矩阵的顺序之间。

我不知道,我需要知道问题是什么,也许是解决方案。

您有4个数据点

您请求4个集群

你预计会发生什么

只有平凡的解决方案(每个点都不同),因此光谱聚类拒绝运行。对于合理的解决方案,聚类数必须至少为2,如果有n个点,则最多为n-1