稀疏数据集上的谱聚类

问题描述 投票:0回答:1

我正在一个数据集上应用谱聚类(

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 时更常发生(至少这是我的简短经验;正如我所提到的,它的行为不是很一致)。

我应该如何处理这个警告和相关错误?这取决于特征的数量吗?如果我添加更多怎么办?

python scikit-learn scipy cluster-analysis spectral-clustering
1个回答
1
投票

我在n_clusters上也遇到了这个问题。由于这是无监督的机器学习,因此 n_clusters 没有单一的正确值。在您的情况下,n_cluster 似乎介于 3 和 7 之间。假设您对聚类有一些基本事实,最好的处理方法是尝试 n_cluster 的几个值,以查看给定数据集是否出现任何模式,同时确保避免任何过度-配件。 您还可以使用轮廓系数(sklearn.metrics.silhouette_score)

© www.soinside.com 2019 - 2024. All rights reserved.