训练多层感知器时,历元和迭代的区别是什么?
当前回答
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是用于训练的样本子集的迭代,例如,神经网络中的梯度下降算法。一个很好的参考: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:当你的网络最终遍历整个训练集(即,每个训练实例一次)时,它完成了一个Epoch。
为了定义迭代(也就是步骤),你首先需要知道批处理的大小:
Batch Size: You probably wouldn't like to process the entire training instances all at one forward pass as it is inefficient and needs a huge deal of memory. So what is commonly done is splitting up training instances into subsets (i.e., batches), performing one pass over the selected subset (i.e., batch), and then optimizing the network through backpropagation. The number of training instances within a subset (i.e., batch) is called batch_size. Iteration: (a.k.a training steps) You know that your network has to go over all training instances in one pass in order to complete one epoch. But wait! when you are splitting up your training instances into batches, that means you can only process one batch (a subset of training instances) in one forward pass, so what about the other batches? This is where the term Iteration comes into play: Definition: The number of forwarding passes (The number of batches that you have created) that your network has to do in order to complete one epoch (i.e., going over all training instances) is called Iteration.
例如,当你有10,000个训练实例,你想用10的大小进行批处理;你必须进行10,000/10 = 1,000次迭代才能完成1个epoch。
希望这能回答你的问题!
根据我的理解,当你需要训练一个NN时,你需要一个包含许多数据项的大型数据集。在训练神经网络时,数据项一个一个地进入神经网络,这称为迭代;当整个数据集通过时,它被称为epoch。
通常,你会把你的测试集分成小批,让网络从中学习,并让训练在你的层数中一步一步地进行,一直应用梯度下降。所有这些小步骤都可以称为迭代。
一个epoch对应于整个训练集通过整个网络一次。限制这种情况是很有用的,例如对抗过拟合。
根据谷歌的机器学习术语表,一个纪元被定义为
“对整个数据集进行完整的训练,以便每个示例都被看到一次。因此,一个epoch表示N/batch_size训练迭代,其中N是示例的总数。”
如果你正在训练10个epoch的模型,批大小为6,给定总共12个样本,这意味着:
该模型将能够在2次迭代(12 / 6 = 2)即单个epoch中看到整个数据集。 总的来说,该模型将有2 X 10 = 20个迭代(每个epoch的迭代X无epoch) 每次迭代后,将对损失和模型参数进行重新评估!