python - 将 scikit-learn TfIdf 与 gensim LDA 结合使用

标签 python scikit-learn text-mining lda

我在 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/

相关文章:

python - Kivy - 如何在不同的屏幕上更改 StringProperty 值?

Python 多处理 : no performance gain with multiple processes

python - 获取错误 AttributeError : 'bool' object has no attribute 'transpose' when attempting to fit machine learning model

java - 根据单词出现频率查找推特中的热门话题

r - R中两个句子之间的词级编辑距离

nlp - 潜在狄利克雷分配与文档聚类之间的关系

python - Ibpy 与 Interactive Brokers API 不工作

python - 如何将 Django 过滤器参数作为参数传递给其他函数

machine-learning - 解释决策树回归的 Graphviz 输出

python - scikit-learn 的 LassoCV 的评分指标