import pyLDAvis.gensim
topicData = pyLDAvis.gensim.prepare(ldamodel, docTermMatrix, dictionary)
pyLDAvis.display(topicData)
执行 pyLDAvis.display 函数时出现以下错误:
TypeError: Object of type 'complex' is not JSON serializable
有人可以在这里指导吗?可能是什么原因?
最佳答案
我有同样的问题。遵循 user3411846 引用的 GH 问题,我找到了一个不同的、更简单的解决方案。
复数来自坐标计算并指定“mds”有效。
https://github.com/bmabey/pyLDAvis/issues/69#issuecomment-311337191
所以你的代码将是
topicData = pyLDAvis.gensim.prepare(ldamodel, docTermMatrix, dictionary, mds='mmds')
mds 的其他选项在这里:https://pyldavis.readthedocs.io/en/latest/modules/API.html#pyLDAvis.prepare
关于json - 类型错误 : Object of type 'complex' is not JSON serializable while using pyLDAvis. display() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46379763/