RandomForestClassifier .fit在ec2上因内存错误而失败,但在本地运行时没有错误

杰基·韦瑟

我正在包含tfidf和尺寸为(42238,155085)的其他要素的熊猫数据框上拟合随机森林分类器。大小为26GB。在本地训练模型时,代码运行没有错误(尽管速度很慢),但是,在内存为4倍的ec2实例上,当内存利用率达到37%时,训练过程会因内存错误而终止。这在6个运行时执行中是一致的。一切都与anaconda 2.7,代码和数据相同,为什么此过程在ec2上失败?

我正在16GB macbook pro上本地运行模型。ec2实例具有64GB内存。

我尝试过的

  1. n_jobs = 1
  2. n_estimators = 10
  3. max_depth = 10
  4. 增加EC2上的交换空间
  5. 将最大锁定内存设置为无限制

ec2实例上的ulimit -a。

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 251728
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 251728
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

model = RandomForestClassifier(max_depth=None, 
                       max_features=0.2, 
                       min_samples_leaf=1, 
                       min_samples_split=2,
                       n_estimators=10, 
                       n_jobs=-1,
                       verbose=1)
model.fit(X_train,y_train)

堆栈跟踪

model.fit(X_train,y_train)
  File "/opt/anaconda2/lib/python2.7/site-packages/sklearn/ensemble/forest.py", line 247, in fit
    X = check_array(X, accept_sparse="csc", dtype=DTYPE)
  File "/opt/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.py", line 433, in check_array
    array = np.array(array, dtype=dtype, order=order, copy=copy)
  File "/opt/anaconda2/lib/python2.7/site-packages/pandas/core/generic.py", line 1603, in __array__
    return com._values_from_object(self)
  File "pandas/_libs/lib.pyx", line 47, in pandas._libs.lib.values_from_object
  File "/opt/anaconda2/lib/python2.7/site-packages/pandas/core/generic.py", line 4684, in get_values
    return self.values
  File "/opt/anaconda2/lib/python2.7/site-packages/pandas/core/generic.py", line 4629, in values
    return self._data.as_array(transpose=self._AXIS_REVERSED)
  File "/opt/anaconda2/lib/python2.7/site-packages/pandas/core/internals.py", line 3949, in as_array
    arr = mgr._interleave()
  File "/opt/anaconda2/lib/python2.7/site-packages/pandas/core/internals.py", line 3960, in _interleave
    result = np.empty(self.shape, dtype=dtype)
MemoryError
杰基·韦瑟

以此为指南:https//www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-7

调整了以下参数,模型能够完成训练。

vm.swappiness=70 鼓励使用交换空间

vm.vfs_cache_pressure=50 鼓励操作系统更多使用缓存

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Colab中的RandomForestClassifier

Maven命令mvn从终端运行时没有错误,但没有从python运行

运行JAR时发生ClassNotFoundException,在IntelliJ IDEA中运行时没有错误

scikit中的RandomForestClassifier与ExtraTreesClassifier学习

在AWS EC2实例上的dockerfile中将git clone作为主机和私有git存储库运行时,主机验证失败错误

在简单的示例上无法从Spark ML运行RandomForestClassifier

RandomForestClassifier.fit在不同机器上使用不同数量的RAM

“ RandomForestClassifier”对象没有属性“ tree_”

Python sklearn RandomForestClassifier不可重现的结果

Sklearn RandomForestClassifier除数0误差除以

在docker容器中的AWS EC2上运行时,Apache Ignite错误的节点发现

ValueError:未知标签类型:RandomForestClassifier中的“未知”

缩放sklearn RandomForestClassifier用于RandomizedSearchCV

了解RandomForestClassifier中的max_features参数

为什么在CPU(使用SKLearn)和GPU(使用RAPID)上使用RandomForestClassifier会得到不同的分数,却大不相同?

RandomForestClassifier-尝试识别sklearn中功能重要性的奇数错误?

RandomForestClassifier引发错误:一个字段包含逗号分隔的值

RandomForestClassifier导入

运行alljoyn项目的.jar的UnsatisfiedLinkError,在Eclipse中运行时没有错误

没有错误,但是运行时什么也没发生(C ++)

scikit学习RandomForestClassifier中的子样本大小

使用 RandomForestClassifier 理解 TreeInterpreter 的输出

RandomForestClassifier 没有属性变换,那么如何得到预测呢?

Java - 在本地运行子进程但在 Heroku 上运行时因“管道损坏”而失败?

在 RandomForestClassifier 上执行 GridSearchCV 会产生较低的准确度

RandomForestClassifier 如何进行分类?

儘管設置了隨機狀態和相同的輸入,sklearn RandomForestClassifier.fit() 仍無法重現

此 RandomForestClassifier 實例尚未安裝

導出/繪製隨機森林決策樹/“RandomForestClassifier”對像沒有屬性“tree_”