我将使用Python的
例如:
scikit-learn
进行文档聚类,目前我拥有一个存储在dict
对象中的稀疏矩阵。例如:
doc_term_dict = { ('d1','t1'): 12, \
('d2','t3'): 10, \
('d3','t2'): 5 \
} # from mysql data table
<type 'dict'>
我希望使用scikit-learn
进行聚类,其中输入矩阵类型为scipy.sparse.csr.csr_matrix
示例:
(0, 2164) 0.245793088885
(0, 2076) 0.205702177467
(0, 2037) 0.193810934784
(0, 2005) 0.14547028437
(0, 1953) 0.153720023365
...
<class 'scipy.sparse.csr.csr_matrix'>
我找不到一种方法将 dict
转换为这个csr矩阵(我从未使用过 scipy
)。