![](/img/trans.png)
[英]TypeError: an integer is required (got type _io.BufferedWriter) using pickle
[英]TypeError: an integer is required (got type str) LDAvis
我是 Python 和数据科学的新手。 我正在尝试处理一些 LDA 可视化,但由于某种原因,我不断收到以下错误。 任何帮助将不胜感激!
import os
LDAvis_data_filepath = os.path.join('./ldavis_prepared_'+str(number_topics))
# # this is a bit time consuming - make the if statement True
# # if you want to execute visualization prep yourself
if 1 == 1:
LDAvis_prepared = sklearn_lda.prepare(lda, count_data, count_vectorizer)
with open(LDAvis_data_filepath, 'wb', 'utf-8') as f:
pickle.dump(LDAvis_prepared, f)
#load the pre-prepared pyLDAvis data from disk
with open(LDAvis_data_filepath,'rb', 'utf-8') as f:
pickle.dump(LDAvis_prepared, f)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-110-4459335c1578> in <module>
----> 1 with open(LDAvis_data_filepath, 'wb', 'utf-8') as f:
2 pickle.dump(LDAvis_prepared, f)
3 # load the pre-prepared pyLDAvis data from disk
4 with open(LDAvis_data_filepath,'rb', 'utf-8') as f:
5 pickle.dump(LDAvis_prepared, f)
TypeError: an integer is required (got type str)
编码是open
的第四个参数,而不是第三个。 看文档两分钟就会告诉你这一点。 而且您的第二个pickle
调用几乎可以肯定是load
,而不是dump
。
with open(LDAvis_data_filepath, 'wb', encoding='utf-8') as f:
pickle.dump(LDAvis_prepared, f)
#load the pre-prepared pyLDAvis data from disk
with open(LDAvis_data_filepath, 'rb', encoding='utf-8') as f:
pickle.load(LDAvis_prepared, f)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.