【问题标题】:Memory error with python 64bitpython 64位的内存错误
【发布时间】:2018-04-29 05:44:19
【问题描述】:

我已添加代码和错误消息。 我已经安装了 python3 64bit 和 anaconda 3.5,当我从文本文件中提取导致二维数组 264,549 X21,000 的特征时,我遇到了内存错误。我正在使用 Windows 10 64 位和 16GB 内存。 当我检查 python 版本时,结果如下: Python 3.6.2 |Anaconda, Inc.| (默认,2017 年 9 月 19 日,08:03:39)[MSC v.1900 64 位 (AMD64)] 在 win32 上

是python的问题吗?或者数组无法装入内存?

这是我遇到的错误:

从训练数据中提取弓的列表... 回溯(最近一次通话最后): 文件“tweet_fea_bow.py”,第 27 行,在 train_bow=vect.fit_transform(训练).toarray() 文件“C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\compressed.py”,第 964 行,在 toarray return self.tocoo(copy=False).toarray(order=order, out=out) 文件“C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\coo.py”,第 252 行,在 toarray B = self._process_toarray_args(order, out) _process_toarray_args 中的文件“C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\base.py”,第 1039 行 返回 np.zeros(self.shape,dtype=self.dtype,order=order) 内存错误

import sys,os,traceback
import numpy as np
import sklearn
from sklearn.feature_extraction.text import CountVectorizer

print(sys.argv)
if len(sys.argv) == 2:
  print( "Reading data from file " + (sys.argv[1]))
  query_file_name = sys.argv[1] 
  tf_num = int(sys.argv[1])
else:
  print ('Number of arguments = %d, expecting 1 arguments, program     terminated.') % (len(sys.argv) - 1)
sys.exit (1)

training=open('../training_data.txt','r').read().splitlines()
print('extracting bow from training data...')
vect=CountVectorizer(min_df=tf_num, ngram_range=(2,2))
train_bow=vect.fit_transform(training).toarray()
print('training matrix size:',train_bow.shape)
print('writing the training matrix...')
outfile=(path+'../bow_bi_gram_%s.npy'%(tf_num))
try:
   np.save(outfile,train_bow)
except:
   print('error')
   e=sys.exc_info()
   print(e)
print('extracting bow from testing data..')
testing=open('../testing_red_len_remove_@andurl.txt','r')
.read().splitlines()
test_bow=vect.transform(testing).toarray()
print('size of testing matrix:',test_bow.shape)
print('writing the testing matrix...')
outfile=('../testing_bow_bi_gram_%s.npy'%(tf_num))
np.save(outfile,test_bow)

【问题讨论】:

  • 如何重现此错误?
  • 您必须向我们提供准确的错误代码,以及更多关于您正在做什么以便我们帮助您的细节。
  • 请给我们看看你原来的错误信息?
  • @ElisByberi 我更新了我的问题以包含代码和错误消息。谢谢
  • @PaydenK.Pringle 我提供了确切的错误消息和代码。谢谢

标签: python numpy machine-learning out-of-memory


【解决方案1】:

自己操作即可:264,549 * 21,000 * 单元格大小 = ?

通常此类数据必须逐块处理。

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 2019-01-31
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    相关资源
    最近更新 更多