我sklearn.cluster.SpectralClustering
在一个具有相当稀疏特征的数据集上应用光谱聚类 ( )。在 Python 中进行谱聚类时,我收到以下警告:
UserWarning: Graph is not fully connected, spectral embedding may not work as expected. warnings.warn("Graph is not fully connected, spectral embedding"
这通常会出现这样的错误:
`
File "****.py", line 120, in perform_clustering_spectral_clustering
predicted_clusters = cluster.SpectralClustering(n_clusters=n).fit_predict(features)
File "****\sklearn\base.py", line 349, in fit_predict
self.fit(X)
File "****\sklearn\cluster\spectral.py", line 450, in fit
assign_labels=self.assign_labels)
File "****\sklearn\cluster\spectral.py", line 256, in spectral_clustering
eigen_tol=eigen_tol, drop_first=False)
File "****\sklearn\manifold\spectral_embedding_.py", line 297, in spectral_embedding
largest=False, maxiter=2000)
File "****\scipy\sparse\linalg\eigen\lobpcg\lobpcg.py", line 462, in lobpcg
activeBlockVectorBP, retInvR=True)
File "****\scipy\sparse\linalg\eigen\lobpcg\lobpcg.py", line 112, in _b_orthonormalize
gramVBV = cholesky(gramVBV)
File "****\scipy\linalg\decomp_cholesky.py", line 81, in cholesky
check_finite=check_finite)
File "****\scipy\linalg\decomp_cholesky.py", line 30, in _cholesky
raise LinAlgError("%d-th leading minor not positive definite" % info)
numpy.linalg.linalg.LinAlgError: 9-th leading minor not positive definite
numpy.linalg.linalg.LinAlgError: 9-th leading minor not positive definite
numpy.linalg.linalg.LinAlgError: the leading minor of order 12 of 'b' is not positive definite. The factorization of 'b' could not be completed and no eigenvalues or eigenvectors were computed.`
然而,当使用相同的设置时,这个警告/错误并不总是发生(即它的行为不是很一致,因此很难测试)。它发生在 n_clusters 的不同值上,但在值 n=2 和 n > 7 时发生的频率更高(至少这是我的简短经验;正如我所提到的,它的行为不是很一致)。
我应该如何处理这个警告和相关错误?它取决于功能的数量吗?如果我添加更多呢?