MemoryError:在sklearn中使用anymodel.fit()时,无法为具有形状和数据类型的数组分配MiB [英] MemoryError: Unable to allocate MiB for an array with shape and data type, when using anymodel.fit() in sklearn
问题描述
获取此内存错误.但是我关注的书/链接没有出现此错误.
Getting this memory error. But the book/link I am following doesn't get this error.
部分代码:
from sklearn.linear_model import SGDClassifier
sgd_clf = SGDClassifier()
sgd_clf.fit(x_train, y_train)
错误: MemoryError:无法为形状为(60000,784)和数据类型为float64的数组分配359.MiB
当我尝试使用StandardScaler的fit_transfrom缩放数据时,也会出现此错误
I also get this error when I try to scale the data using StandardScaler's fit_transfrom
但是,如果我减小训练集的大小(例如: x_train [:1000]
, y_train [:1000]
),这两种方法都可以正常工作
But works fine in both if I decrease the size of training set (something like : x_train[:1000]
,y_train[:1000]
)
在此处中找到该书中代码的链接.我得到的错误是在第60行和第63行(在[60] 中的和在[63]
中的)
Link for the code in the book here. The error I get is in Line 60 and 63 (In [60]
and In [63]
)
这本书:AurélienGéron-使用Scikit-Learn Keras和Tensorflow 2nd Ed进行动手机器学习(页:149/1130)
The book : Aurélien Géron - Hands-On Machine Learning with Scikit-Learn Keras and Tensorflow 2nd Ed (Page : 149 / 1130)
这和我的公羊有关系吗?以及无法分配359"是什么?吝啬的?是内存大小吗?
Does this has anything to do with my ram? and what does "Unable to allocate 359" mean? is it the memory size ?
以防万一我的规格:CPU-ryzen 2400g,ram-8gb(使用jupyter笔记本电脑时免费提供3.1gb)
Just in case my specs : CPU - ryzen 2400g , ram - 8gb (3.1gb is free when using jupyter notebook)
推荐答案
升级python-64位似乎解决了所有的内存错误"问题.问题.
Upgrading python-64 bit seems to have solved all the "Memory Error" problem.
这篇关于MemoryError:在sklearn中使用anymodel.fit()时,无法为具有形状和数据类型的数组分配MiB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!