做图时遇到内存错误

MemoryError: Unable to allocate 1.43 TiB for an array with shape (3700, 5300) and data type float64

源代码如下:

# 第二步 绘制决策边界
def plot_decision_boundary(pred_func):x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5    h = 0.01xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))# 用预测函数预测一下Z = pred_func(np.c_[xx.ravel(), yy.ravel()])Z = Z.reshape(xx.shape)# 然后画出图plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Spectral)from sklearn.linear_model import LogisticRegressionCV# 训练逻辑回归分类器
clf = sklearn.linear_model.LogisticRegressionCV()
clf.fit(X, y)# 画一下决策边界
#plot_decision_boundary(lambda x: clf.predict(x))
plt.figure(figsize=(16, 8))
plot_decision_boundary(clf.predict)
plt.title("Logistic Regression")
plt.show()

做出的努力

搜很多但都是关于计算机内存设置的,结果并没有很有用,而且很麻烦

最终采取的解决办法

修改h,从0.01到1
解决问题的思路:因为大概了解到这个是关于计算机内存不够的原因,而 h 是关于步长设置,步长设置大一点整体计算量就会小一点

# 第二步 绘制决策边界
def plot_decision_boundary(pred_func):x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5    h = 0.01xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))# 用预测函数预测一下Z = pred_func(np.c_[xx.ravel(), yy.ravel()])Z = Z.reshape(xx.shape)# 然后画出图plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Spectral)from sklearn.linear_model import LogisticRegressionCV# 训练逻辑回归分类器
clf = sklearn.linear_model.LogisticRegressionCV()
clf.fit(X, y)# 画一下决策边界
#plot_decision_boundary(lambda x: clf.predict(x))
plt.figure(figsize=(16, 8))
plot_decision_boundary(clf.predict)
plt.title("Logistic Regression")
plt.show()

问题就解决啦

MemoryError: Unable to allocate 1.43 TiB for an array with shape (3700, 5300) and data type float64相关推荐

  1. Linux | MemoryError: Unable to allocate 2.10 GiB for an array内存溢出问题解决

    在机器学习训练中,因载入的矩阵过于庞大,在本机训练是总会报 MemoryError的错,又因本人需要将10G多的内容同时载入一同训练,无法使用其他博客(推荐下面链接处所给博客)所用到的方法,只能从硬件 ...

  2. memoryerror: Unable to allocate array with shape (60000, 28, 28) and data ty

    使用tf缩放图片遇到 (train_images, train_labels), (test_images,test_labels) = keras.datasets.fashion_mnist.lo ...

  3. numpy.core._exceptions.MemoryError: Unable to allocate 167. MiB for an array with shape (2970, 2460,

    估计是batchsize太大,最后一千多张图片出不来

  4. MemoryError: Unable to allocate array with shape (61721, 16000) and data typ

    疑惑 解惑 数据量太大了,也就是cpu内存小导致的: 可以从以下几个方面去改进: 0.换一个性能好的电脑,主要是硬件的问题 1.numpy 在定义数组的时候,采用更低的精度.从float64降低为fl ...

  5. Python Unable to allocate MiB for an array with shape

    最近在运行一个python项目,不过并不熟悉python,因为一直在做java开发的工作.最近改了一个python项目里的SQL,查询的数据量更大了,运行后抛出异常,所以初步怀疑是内存不够 pycha ...

  6. Unable to allocate xxx GiB for an array with shape (xxxx, xxxx)

    今天用Pycharm跑代码的时候报了个错误:Unable to allocate 14.1 GiB for an array with shape (xxxx, xxxx),主要是进行矩阵运算时涉及的 ...

  7. ORA-04031: Unable To Allocate 32 Bytes Of Shared Memory

    记录一次生产库遇到的4031错误,后来通过调整sga大小将问题解决了 报错信息: ORA-04031: 无法分配 32 字节的共享内存 ("shared pool","s ...

  8. ORA-39095: Dump file space has been exhausted: Unable to allocate 8192 bytes

    甲骨文Oracle数据库使用EXPDP/IMPDP进行Oracle数据迁移从高版本(11g)到底版本(10g)步骤 Oralce数据导入 可能产生的错误 ORA-39095: Dump file sp ...

  9. Pulsar bk报错Unable to allocate memory, exiting bookie

    报错 开发人员反映pulsar不可用 每个pulsar bk节点查看 ./bookkeeper shell bookiesanity 发现有2个bk不可用,查看对应日志发现如下 15:36:52.50 ...

最新文章

  1. 无人机、IoT 设备都有漏洞?专访以色列老牌安全企业Check Point | 拟合
  2. Pytorch中改变形状和交换维度详解:view()、reshape()、transpose()、permute()以及contiguous()
  3. CCAI 2019 | 郑南宁:“自觉性AI技术”可助力无人驾驶
  4. 关于Font Awesome图标的使用
  5. java多线程之线程的同步与锁定(转)
  6. hive中操作struct与map三例
  7. 页面缓存处理的几种方法
  8. python基础(十三)
  9. [Swust OJ 85]--单向公路(BFS)
  10. java ajax简单实例_JAVA编写的AJAX例子,很简单,但是很容易理解详解
  11. 文档管理系统 OpenKM
  12. hnu 暑期实训之最少钱币数
  13. android实例教程_Android共享首选项示例教程
  14. Sinevibes Plugins Bundle for Mac(Sinevibes合成器合集)
  15. mysql5.7如何打开,mysql57怎么打开
  16. 教你如何用bat程序给电脑清理缓存垃圾(普通版)
  17. linux系统怎么改待机时间,LINUX操作系统——易用程度/待机时间/连接功能_手机_手机其它OS-中关村在线...
  18. 江西省中小学生学籍管理-登录(1)
  19. js修改div标签中的内容
  20. 读薄《高性能MySql》(三)索引优化

热门文章

  1. html追加没有样式,js/jquery动态添加html,样式和方法不生效的解决方案
  2. 网页3D之babylon.js
  3. 华为软开云8--发布
  4. 冒泡排序原理详解及代码实现
  5. FPGA AD0809 Verilog implement
  6. Latex排版(取除行号)
  7. 华为云618活动时间、活动入口、活动内容详细解读
  8. Realplayer11 v6.0.14.738英文官方原版
  9. HackMyvm(二十)Driftingblues8系列文章持续更新
  10. 1.OpenHarmony