4

如下使用pyLDAvis包时,在我的jupyter笔记本中,

pyLDAvis.enable_notebook()

lda_tfidf = LatentDirichletAllocation(n_components=20, random_state=0)
lda_tfidf.fit(dtm_tfidf)
pyLDAvis.sklearn.prepare(lda_tf, dtm_tf, tf_vectorizer)

生成的绘图自动调整我的 jupyter 笔记本的宽度,使所有其他单元格与边界重叠 - 我尝试过:

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:95% !important; }</style>"))

没有运气,以及

# Using gensim[![enter image description here][1]][1]
v = pyLDAvis.gensim.prepare(lda_model, doc_term_matrix, dictionary)
pyLDAvis.display(v)

花一些时间搜索文档......似乎没有任何关于这就是文档的内容,之前有没有人研究过代码并可以指出我正确的方向?

似乎没有任何其他帖子,但检查了版本等......没有运气

重叠的图像如下所示:

重叠

4

1 回答 1

2

您是否尝试过使用 %matplotlib inline ?我有一个类似的代码,显示它很好。这是我的例子:

%matplotlib inline
vis = pyLDAvis.gensim.prepare(topic_model=lda_model, corpus=corpus, dictionary=dictionary_LDA)
pyLDAvis.enable_notebook()
pyLDAvis.display(vis)

编辑:我在 Jupyter Notebook 中确实遇到了同样的问题(重叠是针对输出区域的)。通过在调用 pyLDAvis.display 之前更改样式,我设法获得更好的显示:

from IPython.core.display import display, HTML
display(HTML("<style>.container { max-width:100% !important; }</style>"))
display(HTML("<style>.output_result { max-width:100% !important; }</style>"))
display(HTML("<style>.output_area { max-width:100% !important; }</style>"))
display(HTML("<style>.input_area { max-width:100% !important; }</style>"))

特别更改 output_area 和 input_area 并设置最大宽度(不是宽度)

于 2020-09-23T22:24:17.270 回答