【发布时间】:2016-03-09 21:30:06
【问题描述】:
我有一个 24866×13 的 1 和 0 矩阵,并想从中发现 biclusters。我尝试了 sci-kit learn 的 spectral co-clustering 和 spectral biclustering 但它们都返回错误“ValueError: array must not contain infs or NaNs.”
矩阵存储为 NumPy 数组,我验证它确实只包含 1 或 0,没有 infs 或 NaN。谱共聚类的错误信息是:
>>> RNAiDf = pd.read_table(dfFile, index_col=0)
>>> RNAiDf.head()
HBEC30 H1155 HCC366 H1819 HCC44 HCC4017 H1993 H460 H2073 \
22848 1 0 0 0 0 1 0 0 0
9625 0 0 0 0 0 0 0 0 0
25 0 0 1 0 0 0 0 0 0
27 0 0 0 0 0 0 0 0 0
10188 0 0 1 0 0 0 0 0 1
H2009 H2122 H1395 HCC95
22848 0 1 0 0
9625 0 1 0 0
25 0 0 0 1
27 0 0 0 0
10188 1 0 0 0
>>> RNAiMatrix = RNAiDf.values
>>> RNAiMatrix.shape
(24866, 13)
>>> model = bicluster.SpectralCoclustering()
>>> model.fit(RNAiMatrix)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/cluster/bicluster.py", line 122, in fit
self._fit(X)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/cluster/bicluster.py", line 271, in _fit
u, v = self._svd(normalized_data, n_sv, n_discard=1)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/cluster/bicluster.py", line 135, in _svd
**kwargs)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/utils/extmath.py", line 296, in randomized_svd
Q = randomized_range_finder(M, n_random, n_iter, random_state)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/utils/extmath.py", line 229, in randomized_range_finder
Q, R = linalg.qr(Y, mode='economic')
File "/work/anaconda3/lib/python3.4/site-packages/scipy/linalg/decomp_qr.py", line 127, in qr
a1 = numpy.asarray_chkfinite(a)
File "/work/anaconda3/lib/python3.4/site-packages/numpy/lib/function_base.py", line 668, in asarray_chkfinite
"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs
对于光谱双聚类:
>>> model = bicluster.SpectralBiclustering()
>>> model.fit(RNAiMatrix)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/cluster/bicluster.py", line 122, in fit
self._fit(X)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/cluster/bicluster.py", line 440, in _fit
u, v = self._svd(normalized_data, n_sv, n_discard)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/cluster/bicluster.py", line 135, in _svd
**kwargs)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/utils/extmath.py", line 296, in randomized_svd
Q = randomized_range_finder(M, n_random, n_iter, random_state)
File "/work/anaconda3/lib/python3.4/site-packages/sklearn/utils/extmath.py", line 229, in randomized_range_finder
Q, R = linalg.qr(Y, mode='economic')
File "/work/anaconda3/lib/python3.4/site-packages/scipy/linalg/decomp_qr.py", line 127, in qr
a1 = numpy.asarray_chkfinite(a)
File "/work/anaconda3/lib/python3.4/site-packages/numpy/lib/function_base.py", line 668, in asarray_chkfinite
"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs
错误似乎源于计算某些矩阵的 QR 分解。设置双簇数的参数似乎没有任何区别。我正在使用 scikit-learn 版本 0.16.1,并且没有一列是恒定的。关于可能出错的任何提示?提前致谢。
【问题讨论】:
-
您需要提供示例数据广告代码。
-
另外,您使用的是哪个版本的 scikit-learn?因为在当前的 master 分支中,这个 random_range_finder 函数发生了一些变化。也许更新最新版本会有所帮助。
-
可能有任何常量列吗?
-
我使用的是 0.16.1 版,没有一列是恒定的。我还更新了我的帖子以包含代码。
-
阅读后拨打
RNAiDf = RNAiDf.dropna()会怎样?
标签: python matrix scikit-learn cluster-analysis