本文介绍了将scikit-learn TfIdf与gensim LDA一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在scikit中使用了TFIDF的各种版本来学习对一些文本数据进行建模.

I've used various versions of TFIDF in scikit learn to model some text data.

vectorizer = TfidfVectorizer(min_df=1,stop_words='english')

结果数据X的格式如下:

The resulting data X is in this format:

<rowsxcolumns sparse matrix of type '<type 'numpy.float64'>'
    with xyz stored elements in Compressed Sparse Row format>

我想尝试使用LDA作为减少稀疏矩阵维数的方法.是否有简单的方法将NumPy稀疏矩阵X馈入gensim LDA模型?

I wanted to experiment with LDA as a way to do reduce dimensionality of my sparse matrix.Is there a simple way to feed the NumPy sparse matrix X into a gensim LDA model?

lda = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=100)

我可以忽略scikit并遵循gensim教程概述的方式,但是我喜欢scikit矢量化器及其所有参数的简单性.

I can ignore scikit and go the way the gensim tutorial outlines, but I like the simplicity of the scikit vectorizers and all of its parameters.

推荐答案

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.

这篇关于将scikit-learn TfIdf与gensim LDA一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 03:27