我正在学习多标签分类,并尝试从scikit学习中实施tfidf教程。我正在处理文本语料库以计算其tf-idf分数。我为此目的使用模块sklearn.feature_extraction.text。使用CountVectorizer和TfidfTransformer,现在我为每个词汇集了语料库矢量和tfidf。问题是我现在有一个稀疏矩阵,例如:
(0, 47) 0.104275891915
(0, 383) 0.084129133023
.
.
.
.
(4, 308) 0.0285015996586
(4, 199) 0.0285015996586
Run Code Online (Sandbox Code Playgroud)
我想将此sparse.csr.csr_matrix转换为列表列表,以便可以摆脱上述csr_matrix的文档ID,并获得tfidf和vocabularyId对,例如
47:0.104275891915 383:0.084129133023
.
.
.
.
308:0.0285015996586
199:0.0285015996586
Run Code Online (Sandbox Code Playgroud)
有什么方法可以转换为列表列表,或者可以通过其他方式更改格式以获得tfidf-vocabularyId对吗?