【问题标题】:LDA visualisation in Jupyter notebookJupyter 笔记本中的 LDA 可视化
【发布时间】:2020-07-09 20:38:52
【问题描述】:

如下使用pyLDAvis包时,在我的jupyter notebook里面,

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)

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

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

重叠的图像如下所示:

:

【问题讨论】:

    标签: python nlp jupyter-notebook data-visualization pyldavis


    【解决方案1】:

    您是否尝试过使用 %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 并设置最大宽度(不是宽度)

    【讨论】:

    • 仍然得到与上面演示的相同的错误...请注意其他图和文本上的失真。
    • 这行得通 - 好主意,我尝试了显示 HTML,但从来没有像你自己那样完全。我认为赏金在回答之前就过期了,但我会看看我能不能把它拿回来。谢谢你的想法
    猜你喜欢
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 2019-05-10
    相关资源
    最近更新 更多