首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LDA主题模型可视化中的错误

LDA主题模型可视化中的错误
EN

Stack Overflow用户
提问于 2018-05-11 10:55:47
回答 1查看 1.5K关注 0票数 1

我想解释我的lda主题模型中的主题,所以我使用的是pyldavis。但不知何故我不能让塔塔跑。以下是代码:

代码语言:javascript
复制
import gensim
from gensim import corpora
from gensim.corpora import Dictionary


dictionary = corpora.Dictionary(lemmatized_list)
print(dictionary)
print(dictionary.token2id)
corpus = [dictionary.doc2bow(text) for text in lemmatized_list]
print(corpus)

ldamodel = gensim.models.ldamodel.LdaModel(corpus, num_topics=5, id2word = 
dictionary, passes=10)
print(ldamodel.print_topics(num_topics=5, num_words=3))

import pyLDAvis.gensim
pyLDAvis.enable_notebook()
pyLDAvis.gensim.prepare(ldamodel, corpus, dictionary)

然后,在我到达代码的最后一部分之后,我必须使用pyldavis进行可视化,它显示了以下错误:

代码语言:javascript
复制
    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-a16bc334f38f> in <module>()
      1 import pyLDAvis.gensim
      2 pyLDAvis.enable_notebook()
----> 3 pyLDAvis.gensim.prepare(ldamodel, corpus, dictionary)
      4 term_ix = np.sort(topic_info.index.unique().values)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pyLDAvis\gensim.py in prepare(topic_model, corpus, dictionary, doc_topic_dist, **kwargs)
    108     """
    109     opts = fp.merge(_extract_data(topic_model, corpus, dictionary, doc_topic_dist), kwargs)
--> 110     return vis_prepare(**opts)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pyLDAvis\_prepare.py in prepare(topic_term_dists, doc_topic_dists, doc_lengths, vocab, term_frequency, R, lambda_step, mds, n_jobs, plot_opts, sort_topics)
    396 
    397    topic_info         = _topic_info(topic_term_dists, topic_proportion, term_frequency, term_topic_freq, vocab, lambda_step, R, n_jobs)
--> 398    token_table        = _token_table(topic_info, term_topic_freq, vocab, term_frequency)
    399    topic_coordinates = _topic_coordinates(mds, topic_term_dists, topic_proportion)
    400    client_topic_order = [x + 1 for x in topic_order]

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pyLDAvis\_prepare.py in _token_table(topic_info, term_topic_freq, vocab, term_frequency)
    265    # term-topic frequency table of unique terms across all topics and all values of lambda
    266    term_ix = topic_info.index.unique()
--> 267    term_ix.sort()
    268    top_topic_terms_freq = term_topic_freq[term_ix]
    269    # use the new ordering for the topics

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexes\base.py in sort(self, *args, **kwargs)
   2098 
   2099     def sort(self, *args, **kwargs):
-> 2100         raise TypeError("cannot sort an Index object in-place, use "
   2101                         "sort_values instead")
   2102 

TypeError: cannot sort an Index object in-place, use sort_values instead

任何关于如何将错误排序为out...would的建议都是非常有用的。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-05-11 11:16:25

这个错误以前已经出现过,并且在某些版本中被确认为Pandas和PyLDAvis之间的不兼容。

这里他们声称一个特定的版本应该修复它。

在2.1.0版本中修复了#76的副本。安装特定版本的pip安装pyldavis==2.1.0

不过我没查过。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50290762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档