0

我正在尝试对一组表示为稀疏 scipy 矩阵 X 的数据点进行聚类。也就是说,

>>> print type(X)
    <class 'scipy.sparse.csr.csr_matrix'>
>>> print X.shape
    (57, 1038)
>>> print X[0]
  (0, 223)  0.471313296962
  (0, 420)  0.621222153695
  (0, 1030) 0.442688836467
  (0, 124)  0.442688836467

但是,当我将此矩阵输入 sklearn.mixture.GMM 模型时,它会引发以下 ValueError:

 File "/Library/Python/2.7/site-packages/sklearn/mixture/gmm.py", line 423, in fit
      X = np.asarray(X, dtype=np.float)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/numeric.py", line 235, in asarray
     return array(a, dtype, copy=False, order=order)
 ValueError: setting an array element with a sequence.

但是,我已经能够使 sklearn.cluster.KMeans 模型在同一个稀疏矩阵 X 上完美运行。

其他一些有用的信息:scipy 版本 = 0.11.0,sklearn 版本 = 0.14.1

关于出了什么问题的任何想法?提前致谢!

4

1 回答 1

4

GMMs don't support sparse matrix input, while KMeans does. If an estimator supports sparse matrices, this is always explicitly stated in the docstring for the relevant method.

于 2013-11-14T14:44:37.693 回答