训练多层感知器时,历元和迭代的区别是什么?
当前回答
要理解它们之间的区别,你必须理解梯度下降算法及其变体。
在我开始回答这个问题之前,我想先了解一下背景。
批处理是完整的数据集。它的大小是可用数据集中训练示例的总数。
小批量大小是学习算法在单次传递(向前和向后)中处理的示例数量。
迷你批是给定迷你批大小的数据集的一小部分。
迭代是算法已经看到的数据批次的数量(或者简单地说,算法已经在数据集上完成的次数)。
epoch是一个学习算法看到完整数据集的次数。现在,这可能不等于迭代的次数,因为数据集也可以小批量处理,本质上,一次传递可能只处理数据集的一部分。在这种情况下,迭代的数量不等于epoch的数量。
在批处理梯度下降的情况下,整个批处理在每个训练通过。因此,梯度下降优化器的收敛比Mini-batch梯度下降更平滑,但需要更多的时间。如果存在最优条件,分批梯度下降法保证能找到最优条件。
随机梯度下降是小批量梯度下降的一种特殊情况,其中小批量大小为1。
其他回答
一个epoch包含几个迭代。这就是这个时代。让我们把epoch定义为训练神经网络时在数据集上的迭代次数。
Epoch和iteration描述的是不同的东西。
时代
epoch描述了算法看到整个数据集的次数。因此,每当算法看到数据集中的所有样本时,就完成了一个epoch。
迭代
迭代描述了一批数据通过算法的次数。在神经网络的例子中,这意味着向前传递和向后传递。因此,每当你通过神经网络传递一批数据时,你就完成了一次迭代。
例子
举个例子可能会更清楚。
假设您有一个包含10个示例(或样本)的数据集。批处理大小为2,并指定算法运行3个epoch。
因此,在每个epoch中,您有5个批次(10/2 = 5)。每个批次都通过算法,因此每个epoch有5个迭代。 因为您已经指定了3个epoch,所以总共有15个迭代(5*3 = 15)用于训练。
根据我的理解,当你需要训练一个NN时,你需要一个包含许多数据项的大型数据集。在训练神经网络时,数据项一个一个地进入神经网络,这称为迭代;当整个数据集通过时,它被称为epoch。
epoch是用于训练的样本子集的迭代,例如,神经网络中的梯度下降算法。一个很好的参考:http://neuralnetworksanddeeplearning.com/chap1.html
请注意,该页面有一个使用epoch的梯度下降算法的代码
def SGD(self, training_data, epochs, mini_batch_size, eta,
test_data=None):
"""Train the neural network using mini-batch stochastic
gradient descent. The "training_data" is a list of tuples
"(x, y)" representing the training inputs and the desired
outputs. The other non-optional parameters are
self-explanatory. If "test_data" is provided then the
network will be evaluated against the test data after each
epoch, and partial progress printed out. This is useful for
tracking progress, but slows things down substantially."""
if test_data: n_test = len(test_data)
n = len(training_data)
for j in xrange(epochs):
random.shuffle(training_data)
mini_batches = [
training_data[k:k+mini_batch_size]
for k in xrange(0, n, mini_batch_size)]
for mini_batch in mini_batches:
self.update_mini_batch(mini_batch, eta)
if test_data:
print "Epoch {0}: {1} / {2}".format(
j, self.evaluate(test_data), n_test)
else:
print "Epoch {0} complete".format(j)
看看代码。对于每个历元,我们随机生成梯度下降算法输入的子集。为什么epoch是有效的,也解释了这一页。请看一看。
Epoch is 1 complete cycle where the Neural network has seen all the data. One might have said 100,000 images to train the model, however, memory space might not be sufficient to process all the images at once, hence we split training the model on smaller chunks of data called batches. e.g. batch size is 100. We need to cover all the images using multiple batches. So we will need 1000 iterations to cover all the 100,000 images. (100 batch size * 1000 iterations) Once Neural Network looks at the entire data it is called 1 Epoch (Point 1). One might need multiple epochs to train the model. (let us say 10 epochs).
推荐文章
- 如何从scikit-learn决策树中提取决策规则?
- 数据挖掘中分类和聚类的区别?
- 主体、使用者和主体之间的意义和区别是什么?
- 什么是分片,为什么它很重要?
- 我在哪里调用Keras的BatchNormalization函数?
- 编程中的术语“上下文”?
- model.eval()在pytorch中做什么?
- 为什么binary_crossentropy和categorical_crossentropy对同一个问题给出不同的性能?
- 覆盖或覆盖
- 火灾vs. Webservice
- 为什么使用softmax而不是标准归一化?
- 为什么两个不同的概念都叫“堆”?
- 一般来说,应该选择哪种机器学习分类器?
- Keras,如何得到每一层的输出?
- 缓冲区是什么意思?