Dark
Dark

Reputation: 189

MemoryError when doing RBF fitting with Scikit-learn

If I run this code, I get a memory error. Does anyone know what I can improve?

Code:

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))

Here I edit y to play with the data and get a second dataset.

y[1:5] = 1

And when I run this code, the error appears:

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

Upvotes: 2

Views: 704

Answers (1)

Gabriel M
Gabriel M

Reputation: 1514

GaussianProcessClassifier()

has the following parameter as stated in the docs:

copy_X_train : bool, optional (default: True)

if you set it to false it will save you a lot of memory.

However, GaussianProcessClassifier consumes a lot of memory even for fairly small datasets. I would recommend you to use a different classifier where you can apply some dimensionality reduction techniques.

Upvotes: 2

Related Questions