我得到一个MemoryError:无法为具有形状(50000,164921)和数据类型float64的数组分配61.4 GiB
tfidf = TfidfVectorizer(analyzer=remove_stopwords)
X = tfidf.fit_transform(df['lemmatize'])
print(X.shape)
Output : (50000, 164921)现在,内存错误出现了
df = pd.DataFrame(X.toarray(), columns=tfidf.get_feature_names())MemoryError:无法为形状(50000,164921)和数据类型float64的数组分配61.4 GiB
发布于 2021-02-20 14:43:00
内存不足,但是可以通过将数据类型从float64更改为uint8来完成。请尝试这个,如果它再次抛出相同的错误,请告诉我。
df = pd.DataFrame(np.array(X).astype(np.uint8))发布于 2022-02-25 04:43:38
我们可以限制正在处理的数据。例如,前1000条记录的窗口函数。
# Creating Document Term Matrix
# I'll use the word matrix as a different view on the data
from sklearn.feature_extraction.text import CountVectorizer
cv=CountVectorizer(analyzer='word')
data=cv.fit_transform(df_grouped['lemmatized_h'][:1000])
# I put limits on the data being fed into the Count vectorizer because of my limited ram
df_dtm = pd.DataFrame(data.toarray(), columns=cv.get_feature_names())
# df_dtm = pd.DataFrame(np.array(data).astype(np.uint8), columns=cv.get_feature_names())
df_dtm.index=df_grouped.index[:1000]
df_dtm.head(3)https://stackoverflow.com/questions/66292616
复制相似问题