我试图显示一个非常稀疏矩阵与预计算距离值tsne但我有麻烦它。sklearn tsne用稀疏矩阵
它归结为:
row = np.array([0, 2, 2, 0, 1, 2])
col = np.array([0, 0, 1, 2, 2, 2])
distances = np.array([.1, .2, .3, .4, .5, .6])
X = csc_matrix((distances, (row, col)), shape=(3, 3))
Y = TSNE(metric='precomputed').fit_transform(X)
不过,我得到这个错误:
TypeError: A sparse matrix was passed, but dense data is required for method="barnes_hut". Use X.toarray() to convert to a dense numpy array if the array is small enough for it to fit in memory. Otherwise consider dimensionality reduction techniques (e.g. TruncatedSVD)
我不想执行TruncatedSVD因为我已经计算出的距离。
如果我改变method='exact'
,我得到另一个错误(这有点可疑):
NotImplementedError: >= and <= don't work with 0.
注:我的距离矩阵是100K左右X 100K大约1M非零值。
任何想法?
的csr_matrix而是我认为这是明显的,我需要稀疏矩阵.. todense产生一个的MemoryError。 –