簡體   English   中英

為什么pyLDAvis圖在條形圖上不顯示主題關鍵詞?

[英]Why pyLDAvis graph does not display topic keywords on the bar chart?

我正在嘗試使用 PyLDAvis 可視化 LDA Model 的結果。 我設法讓圖表顯示在 jupyter notebook 中,但是,描述主題的關鍵字標簽(在條形圖上)丟失了。

下面是使用虛擬數據的代碼示例。

import numpy as np
import pandas as pd
import gensim
import gensim.corpora as corpora
import matplotlib.pyplot as plt
import pyLDAvis
import pyLDAvis.gensim 

texts = [['today', 'cold', 'winter', 'lot', 'snow', 'everywhere'],
       ['winter', 'snow', 'snowman'],
       ['summer', 'day', 'sunny', 'lake'],
       ['sunny', 'garden', 'today'],
       ['winter', 'snowing', 'today'],
       ['picnic', 'garden', 'sunny', 'weekend']]

# Create Dictionary
dictionary = corpora.Dictionary(texts)

# Create Corpus
corpus = [dictionary.doc2bow(text) for text in texts]

# Train model
lda_model = gensim.models.ldamodel.LdaModel(corpus=corpus,
                                           id2word=dictionary,
                                           num_topics=3, 
                                           random_state=100,
                                           update_every=1,
                                           chunksize=100,
                                           passes=10,
                                           alpha='auto',
                                           per_word_topics=True)

# Visualise topics
pyLDAvis.enable_notebook()
plot = pyLDAvis.gensim.prepare(lda_model, corpus, dictionary)
plot

這是顯示的 plot 的屏幕截圖

這是一個應該是什么樣子的示例https://nbviewer.jupyter.org/github/bmabey/hacker_news_topic_modelling/blob/master/HN%20Topic%20Model%20Talk.ipynb

我嘗試將本地參數設置為 True 但沒有任何區別。 pyLDAvis.enable_notebook(local = True)

我嘗試將 output 保存為 html 但它產生了一個空文件。 pyLDAvis.save_html(plot, 'lda.html')

我正在使用 python 3.7.1

有什么建議么?

.pip install pyLDAvis==2.1.2

我也遇到了這個問題,這有幫助。 舊版本的pyLDAvis不能與 Jupyter 或 Colab 一起正常工作。

我遇到了同樣的問題,我只是使用這個:

pyLDAvis.save_html(繪圖,'vis.html')

因此完整的可視化將作為 html 文件保存在 wd 中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM