【发布时间】:2015-10-04 09:16:11
【问题描述】:
我刚刚尝试使用 sklearn.decomposition 中的 IncrementalPCA,但它像之前的 PCA 和 RandomizedPCA 一样抛出了 MemoryError。我的问题是,我要加载的矩阵太大而无法放入 RAM。现在它作为形状数据集存储在 hdf5 数据库中 ~(1000000, 1000),所以我有 1.000.000.000 个 float32 值。我认为 IncrementalPCA 分批加载数据,但显然它试图加载整个数据集,这没有帮助。这个库是如何使用的? hdf5格式有问题吗?
from sklearn.decomposition import IncrementalPCA
import h5py
db = h5py.File("db.h5","r")
data = db["data"]
IncrementalPCA(n_components=10, batch_size=1).fit(data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/software/anaconda/2.3.0/lib/python2.7/site-packages/sklearn/decomposition/incremental_pca.py", line 165, in fit
X = check_array(X, dtype=np.float)
File "/software/anaconda/2.3.0/lib/python2.7/site-packages/sklearn/utils/validation.py", line 337, in check_array
array = np.atleast_2d(array)
File "/software/anaconda/2.3.0/lib/python2.7/site-packages/numpy/core/shape_base.py", line 99, in atleast_2d
ary = asanyarray(ary)
File "/software/anaconda/2.3.0/lib/python2.7/site-packages/numpy/core/numeric.py", line 514, in asanyarray
return array(a, dtype, copy=False, order=order, subok=True)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (-------src-dir-------/h5py/_objects.c:2458)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (-------src-dir-------/h5py/_objects.c:2415)
File "/software/anaconda/2.3.0/lib/python2.7/site-packages/h5py/_hl/dataset.py", line 640, in __array__
arr = numpy.empty(self.shape, dtype=self.dtype if dtype is None else dtype)
MemoryError
感谢您的帮助
【问题讨论】:
标签: python scikit-learn bigdata hdf5 pca