加入收藏 | 设为首页 | 会员中心 | 我要投稿 莱芜站长网 (https://www.0634zz.com/)- 云连接、建站、智能边缘云、设备管理、大数据!
当前位置: 首页 > 编程开发 > Python > 正文

python – 使用sсikit-learn TfIdf和gensim LDA

发布时间:2020-09-25 05:48:32 所属栏目:Python 来源:互联网
导读:我在scikit中使用了各种版本的TFIDF来学习一些文本数据的建模. vectorizer = TfidfVectorizer(min_df=1,stop_words=english) 生成的数据X采用以下格式: rowsxcolumns sparse matrix of type type numpy.float64 with xyz stored elements

我在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矢量化器及其所有参数的简单性.

谢谢,

G

解决方法

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.

(编辑:莱芜站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读