小编Kra*_*urt的帖子

大数据上的增量PCA

我刚刚尝试使用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)

python hdf5 bigdata pca scikit-learn

11
推荐指数
1
解决办法
6639
查看次数

keras lstm层中的多个内核是什么意思?

https://keras.io/layers/recurrent/ 上,我看到 LSTM 层有 akernel和 a recurrent_kernel。它们的含义是什么?根据我的理解,我们需要 LSTM 单元的 4 个门的权重。但是,在 keras 实现中,kernel形状为 (input_dim, 4*units),recurrent_kernel形状为 (units, 4*units)。那么,他们都以某种方式实现了门吗?

neural-network lstm keras

7
推荐指数
1
解决办法
1549
查看次数

在contextmanager中使用yield两次

我试图用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吗?

谢谢

python yield contextmanager mpd

2
推荐指数
1
解决办法
1494
查看次数

标签 统计

python ×2

bigdata ×1

contextmanager ×1

hdf5 ×1

keras ×1

lstm ×1

mpd ×1

neural-network ×1

pca ×1

scikit-learn ×1

yield ×1