json - 类型错误 : Object of type 'complex' is not JSON serializable while using pyLDAvis. display() 函数

标签 json gensim serializable

我有一个包含九个文档的文档术语矩阵:

enter image description here

我正在运行代码如下:

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/

相关文章:

javascript - 如何删除一个json元素?

python - 将 Fasttext 向量转换为单词

jquery - 将 JSON 数据发布到 .asmx Web 服务

jquery getJSON 基于所选选项

java - JAXB:解码异构数组

python - 如何通过 Doc2Vec 找到文档中最关键的句子或单词?

python - 应用LDA后如何自动标记主题

sql-server - Sql Server 忽略行锁提示

java - Java 中的可序列化、可克隆和内存使用

java Serialized接口(interface)没有功能,为什么会影响 "writeObject"/"readObject"