使用Scikit-learn进行RBF拟合时出现MemoryError

时间:2018-08-01 07:02:31

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

如果运行此代码,则会出现内存错误。有谁知道我可以改善什么?

代码:

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)

1 个答案:

答案 0 :(得分:2)

GaussianProcessClassifier()

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

copy_X_train :布尔型,可选(默认值:True)

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

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