I am new to Python and Data Science in general. I am trying to work on some LDA visualizations, but for some reason I keep getting the following error. Any help would be greatly appreciated!
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)
The encoding is the 4th parameter to open
, not the 3rd. Two minutes looking at the documentation would have told you that. And your second pickle
call should almost certainly be load
, not 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.