Python中的“ display_formatter”属性错误

DIG*_*SUM 1 python error-handling lda

我正在研究一个主题建模脚本,该脚本使用gensim包基于文档集合创建模型。

当准备使用pyLDAvis软件包可视化模型时,遇到了以下错误:

import pyLDAvis
pyLDAvis.enable_notebook()

Traceback (most recent call last):
  File "/dev2.py", line 2, in <module>
    pyLDAvis.enable_notebook()
  File "/Users/username/Library/Python/3.6/lib/python/site-packages/pyLDAvis/_display.py", line 311, in enable_notebook
    formatter = ip.display_formatter.formatters['text/html']
AttributeError: 'NoneType' object has no attribute 'display_formatter'
Run Code Online (Sandbox Code Playgroud)

Ben*_*bey 5

enable_notebook功能仅在使用笔记本电脑时适用。如果要编写将可视化内容输出为HTML文档的脚本,则不需要(也不应该)调用该函数。相反,我认为您只需要使用prepare和save_html函数。

  • 谢谢!这是对的。只需执行“ visualisation = pyLDAvis.gensim.prepare(lda_model,语料库,字典)”,然后执行“ pyLDAvis.save_html(visualisation,'LDA_Visualization.html')”即可! (2认同)