I have a document Term matrix with nine documents:
I am running the code as below:
import pyLDAvis.gensim
topicData = pyLDAvis.gensim.prepare(ldamodel, docTermMatrix, dictionary)
pyLDAvis.display(topicData)
I am getting the below error when executing pyLDAvis.display function:
TypeError: Object of type 'complex' is not JSON serializable
Can someone guide here? What could be the reason?
I had the same problem. Following the GH issue referenced by user3411846 I found a different, simpler solution.
The complex number had come from coordinate calculation and specifying the "mds" worked.
https://github.com/bmabey/pyLDAvis/issues/69#issuecomment-311337191
So your code would be
topicData = pyLDAvis.gensim.prepare(ldamodel, docTermMatrix, dictionary, mds='mmds')
Other options for mds are here: https://pyldavis.readthedocs.io/en/latest/modules/API.html#pyLDAvis.prepare
Add this line of code to your pyLDAvis pyLDAvis/utils.py
if np.iscomplexobj(obj):
return abs(obj)
This error has been reported in GitHub GitHub Issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With