簡體   English   中英

TypeError:需要一個 integer(獲取類型 str)LDAvis

[英]TypeError: an integer is required (got type str) LDAvis

我是 Python 和數據科學的新手。 我正在嘗試處理一些 LDA 可視化,但由於某種原因,我不斷收到以下錯誤。 任何幫助將不勝感激!

類型錯誤:需要 integer(獲取類型 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)

編碼是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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM