【问题标题】:MemoryError: Unable to allocate 8.27 GiB for an array with shape (323313, 3435) and data type float64MemoryError:无法为形状(323313、3435)和数据类型 float64 的数组分配 8.27 GiB
【发布时间】:2021-03-05 22:35:15
【问题描述】:

我的数据框中有扩展名(例如 .exe、.py、.xml、.doc 等)表。在终端上运行后 我在大型数据集上遇到错误。

encoder = OneHotEncoder(handle_unknown='ignore')
encoder.fit(features['Extension'].values.reshape(-1, 1))
temp = encoder.transform(features['Extension'].values.reshape(-1, 1)).toarray()  #GETTING ERROR on this
print("Size of array in bytes",getsizeof(temp))
print("Array :-",temp)
print("Shape :- ",features.shape, temp.shape)
features.drop(columns=['Extension'], axis=1, inplace=True)
dump(encoder, os.path.join(os.getcwd(), 'model_dumps', 'encoder.pkl'))
features.drop(columns=['Extension'], axis=1, inplace=True)
features = featureScaling(features)
features = np.concatenate((features, temp), axis=1)

输出 -

1) Size of array in bytes :- 8884558912
2) Array :- 
[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [1. 0. 0. ... 0. 0. 0.]
 [1. 0. 0. ... 0. 0. 0.]
 [1. 0. 0. ... 0. 0. 0.]]
3)Shape :- (323310, 8) (323310, 3435)

【问题讨论】:

标签: python pandas numpy machine-learning one-hot-encoding


【解决方案1】:

这很有趣。

MemoryError: 无法为形状为 (323313, 3435) 且数据类型为 float64 的数组分配 8.27 GiB

大多数现代计算机的 RAM 不超过 8 Gb。看起来你有 8 个,python 无法将所有这些数据都放入内存中。尝试购买另一台具有更多内存的计算机或升级您现有的计算机。这肯定会解决问题。

【讨论】:

  • 这与 8Gb 内存无关。将来如果我有数百万行,即使是 32Gb RAM 对我来说也太少了。我需要通用的解决方案。
  • @sheel 现在问题出在 RAM 上。要使用数据,您需要将其存储在 RAM 中。如果您没有足够的 RAM,则无法使用数据。如果你不能使用数据,你的代码就会崩溃。
  • 我想起了一件事。您可以在云 IDE 中编写代码,例如 CS50 IDE (ide.cs50.io)。如果云 IDE 有足够的 RAM,一切都会按预期工作。
猜你喜欢
  • 1970-01-01
  • 2021-01-04
  • 1970-01-01
  • 1970-01-01
  • 2020-12-02
  • 2023-01-23
  • 2020-01-14
  • 1970-01-01
  • 2020-08-30
相关资源
最近更新 更多