这个随机如何获取数据的作品?

问题描述 投票:0回答:1

在get_batch功能,它怎么能保证每个随机取从x和y的指数法是独一无二的?由于其随机性,它得到x和y的所有数据在“get_batch”迭代结束了吗?

取而代之的随机读取,它不应该得到的数据顺序?

x = np.arange(0, 5, 0.1)
y = x**3 - 4*x**2 - 2*x + 2

def get_batch(x, y, batch_size=20):
    idxs = np.random.randint(0, len(x), (batch_size))
    return x[idxs], y[idxs]

然后拿到批调用:

x_batch, y_batch = get_batch(x, y)

我做了一个模拟实验:

In [48]: for i in range(3): 
    ...:     print(np.random.randint(0, 5, 10)) 
    ...:                                                                                                                                                      
[3 0 2 0 4 2 2 1 4 3]
[1 2 1 3 0 0 0 4 2 2]
[3 0 0 3 0 2 0 2 1 1]
python numpy machine-learning
1个回答
0
投票

这种方法不能确保它得到x和y的所有数据在get_batch迭代结束。更好的方法是在每个历元的开始洗牌的数据,然后顺序地产生的批次。当然,如果你正在做Bootstrapping从数据适合不同样品不同型号(带替换),这是一种有效的方法。

© www.soinside.com 2019 - 2024. All rights reserved.