微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

pyLDAvis: 可视化错误 (IndexError: index 3537 is out of bounds for axis 1 with size 3537)

如何解决pyLDAvis: 可视化错误 (IndexError: index 3537 is out of bounds for axis 1 with size 3537)

我正在尝试通过 pyLDAvis 可视化一些数据。 我的代码看起来像这样

dictionary_LDA = corpora.Dictionary(descriptions_lem_stop_sense_grams)
dictionary_LDA.filter_extremes(no_below=3)
corpus = [dictionary_LDA.doc2bow(list_of_tokens) for list_of_tokens in descriptions_lem_stop_sense_grams]

num_topics = 20
lda_model = models.Ldamodel(corpus,num_topics=num_topics,\
                                  id2word=dictionary_LDA,\
                                  passes=4,alpha=[0.01]*num_topics,\
                                  eta=[0.01]*len(dictionary_LDA.keys()))

for i,topic in lda_model.show_topics(formatted=True,num_words=10):
    print(str(i)+": "+ topic)
    print()
0: 0.012*"monster" + 0.009*"set" + 0.009*"world" + 0.009*"point" + 0.008*"end" + 0.008*"investigator" + 0.008*"add" + 0.007*"board" + 0.007*"kNow" + 0.007*"score"

1: 0.022*"game" + 0.013*"card" + 0.010*"take" + 0.010*"include" + 0.009*"two" + 0.009*"try" + 0.008*"point" + 0.007*"end" + 0.007*"play" + 0.007*"army"

2: 0.016*"game" + 0.015*"take" + 0.013*"word" + 0.010*"action" + 0.008*"give" + 0.008*"create" + 0.008*"play" + 0.007*"start" + 0.007*"well" + 0.007*"must"

...

其中 descriptions_lem_stop_sense_grams 是单词列表的列表。

dic=corpora.Dictionary(descriptions_lem_stop_sense_grams)

vis = pyLDAvis.gensim.prepare(lda_model,corpus,dic)

pyLDAvis.enable_notebook()
pyLDAvis.display(vis)

最后的代码结果是错误

IndexError: index 3537 is out of bounds for axis 1 with size 3537

谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。