我在 scikit 中使用了各种版本的 TFIDF 来学习建模一些文本数据。
vectorizer = TfidfVectorizer(min_df=1,stop_words='english')
结果数据 X 的格式如下:
<rowsxcolumns sparse matrix of type '<type 'numpy.float64'>'
with xyz stored elements in Compressed Sparse Row format>
我想尝试使用 LDA 来降低稀疏矩阵的维数。 有没有一种简单的方法可以将 NumPy 稀疏矩阵 X 馈送到 gensim LDA 模型中?
lda = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=100)
我可以忽略 scikit 并按照 gensim 教程概述的方式进行操作,但我喜欢 scikit 向量化器及其所有参数的简单性。
最佳答案
http://radimrehurek.com/gensim/matutils.html
class gensim.matutils.Sparse2Corpus(sparse, documents_columns=True)
Convert a matrix in scipy.sparse format into a streaming gensim corpus.
关于python - 将 scikit-learn TfIdf 与 gensim LDA 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19504898/