Speicherfehler bei Python beim Konvertieren in ein Array
Mein Code wird unten angezeigt:
from sklearn.datasets import load_svmlight_files
import numpy as np
perm1 =np.random.permutation(25000)
perm2 = np.random.permutation(25000)
X_tr, y_tr, X_te, y_te = load_svmlight_files(("dir/file.feat", "dir/file.feat"))
#randomly shuffle data
X_train = X_tr[perm1,:].toarray()[:,0:2000]
y_train = y_tr[perm1]>5 #turn into binary problem
Der Code funktioniert bis hier gut, aber wenn ich versuche, ein weiteres Objekt in ein Array zu konvertieren, gibt mein Programm einen Speicherfehler zurück.
Code:
X_test = X_te[perm2,:].toarray()[:,0:2000]
Error:
---------------------------------------------------------------------------
MemoryError Traceback (most recent call last)
<,ipython-input-7-31f5e4f6b00c> in <module>()
----> 1 X_test = X_test.toarray()
C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\compressed.pyc in toarray(self, order, out)
788 def toarray(self, order=None, out=None):
789 """See the docstring for `spmatrix.toarray`."""
--> 790 return self.tocoo(copy=False).toarray(order=order, out=out)
791
792 ##############################################################
C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\coo.pyc in toarray(self, order, out)
237 def toarray(self, order=None, out=None):
238 """See the docstring for `spmatrix.toarray`."""
--> 239 B = self._process_toarray_args(order, out)
240 fortran = int(B.flags.f_contiguous)
241 if not fortran and not B.flags.c_contiguous:
C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\base.pyc in _process_toarray_args(self, order, out)
697 return out
698 else:
--> 699 return np.zeros(self.shape, dtype=self.dtype, order=order)
700
701
MemoryError:
Ich bin neu in Python und weiß nicht, ob der Speicherfehler manuell behoben werden muss.
Andere Teile meines Codes geben dieselben Fehler zurück (wie das Training mit knn oder ann).
Wie kann ich das beheben?