【问题标题】:TypeError: an integer is required (got type str) LDAvisTypeError:需要一个整数(获取类型 str)LDAvis
【发布时间】:2021-06-14 10:02:10
【问题描述】:

总的来说,我是 Python 和数据科学的新手。我正在尝试处理一些 LDA 可视化,但由于某种原因,我不断收到以下错误。任何帮助将不胜感激!

Type Error: an integer is required (got type str)

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)

【问题讨论】:

    标签: pickle lda pyldavis


    【解决方案1】:

    编码是第4个参数到@ 987654321,而不是第3个参数。两分钟看文件会告诉你。而你的第二个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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 2018-04-24
      相关资源
      最近更新 更多