【问题标题】:MemoryError when doing RBF fitting with Scikit-learn使用 Scikit-learn 进行 RBF 拟合时出现 MemoryError
【发布时间】:2019-01-08 16:00:20
【问题描述】:

如果我运行此代码,我会收到内存错误。有谁知道我可以改进什么?

代码:

import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import RBF
import cv2

input = "testProbe.jpg"
# load the image, convert it to grayscale
image = cv2.imread(input)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# threshold the image to reveal light regions in the gray image
thresh = cv2.threshold(gray, 145, 200, cv2.THRESH_BINARY)[1]

# import data
X = np.where(thresh>0)

xx = np.array(X)
xx = np.ravel(xx,order='F')
zz = xx.reshape((int(len(xx)/2),2))
y = np.asarray(np.zeros((widthX, 1), dtype=int))

在这里我编辑 y 来处理数据并获得第二个数据集。

y[1:5] = 1

当我运行这段代码时,出现错误:

gpc_rbf_isotropic = GaussianProcessClassifier().fit(zz, y)

【问题讨论】:

  • 你的数据集有多大?
  • @GabrielM 大小为 338742

标签: python python-3.x memory scikit-learn out-of-memory


【解决方案1】:

GaussianProcessClassifier()

具有docs中所述的以下参数:

copy_X_train:bool,可选(默认:True)

如果您将其设置为 false,它将为您节省大量内存。

但是,GaussianProcessClassifier 即使对于相当小的数据集也会消耗大量内存。我建议您使用不同的分类器,您可以在其中应用一些降维技术。

【讨论】:

  • 感谢您的回答。不幸的是,它没有帮助
猜你喜欢
  • 2014-08-06
  • 2015-06-23
  • 2013-07-21
  • 2018-12-01
  • 2021-05-09
  • 2019-10-22
  • 2017-11-29
  • 1970-01-01
  • 2016-02-05
相关资源
最近更新 更多