我刚刚尝试使用sklearn.decomposition中的IncrementalPCA,但它之前就像PCA和RandomizedPCA一样抛出了MemoryError.我的问题是,我试图加载的矩阵太大而无法放入RAM中.现在它作为shape~(1000000,1000)的数据集存储在hdf5数据库中,所以我有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 …Run Code Online (Sandbox Code Playgroud) 在https://keras.io/layers/recurrent/ 上,我看到 LSTM 层有 akernel和 a recurrent_kernel。它们的含义是什么?根据我的理解,我们需要 LSTM 单元的 4 个门的权重。但是,在 keras 实现中,kernel形状为 (input_dim, 4*units),recurrent_kernel形状为 (units, 4*units)。那么,他们都以某种方式实现了门吗?
我试图用contextmanager隐藏一些try/except复杂性.这是一个简单的例子:
from contextlib import contextmanager
import mpd
mpdclient = mpd.MPDClient()
mpdclient.connect("localhost", 6600)
@contextmanager
def mpdcontext():
try:
yield
except mpd.ConnectionError:
mpdclient.connect("localhost", 6600)
with mpdcontext():
mpdclient.status()
with mpdcontext():
mpdclient.lsinfo()
Run Code Online (Sandbox Code Playgroud)
现在,正如我所理解的那样,在调用yield时执行with语句中的块.在我的情况下,如果这引发异常,我重新连接到mpd.重新连接后,我可以以某种方式再次执行with-block吗?
谢谢