keras-cn icon indicating copy to clipboard operation
keras-cn copied to clipboard

关于keras文档中FAQ"为什么训练误差比测试误差高很多?"的疑问

Open dorbodwolf opened this issue 8 years ago • 3 comments

中文文档是这样说的:

一个Keras的模型有两个模式:训练模式和测试模式。一些正则机制,如Dropout,L1/L2正则项在测试模式下将不被启用。

另外,训练误差是训练数据每个batch的误差的平均。在训练过程中,每个epoch起始时的batch的误差要大一些,而后面的batch的误差要小一些。另一方面,每个epoch结束时计算的测试误差是由模型在epoch结束时的状态决定的,这时候的网络将产生较小的误差。

【Tips】可以通过定义回调函数将每个epoch的训练误差和测试误差并作图,如果训练误差曲线和测试误差曲线之间有很大的空隙,说明你的模型可能有过拟合的问题。当然,这个问题与Keras无关。【@BigMoyan】

英文文档是这样的

A Keras model has two modes: training and testing. Regularization mechanisms, such as Dropout and L1/L2 weight regularization, are turned off at testing time.

Besides, the training loss is the average of the losses over each batch of training data. Because your model is changing over time, the loss over the first batches of an epoch is generally higher than over the last batches. On the other hand, the testing loss for an epoch is computed using the model as it is at the end of the epoch, resulting in a lower loss.

这里的测试误差是指划分的validation data还是指testing data?

dorbodwolf avatar Oct 11 '16 07:10 dorbodwolf

@dorbodwolf 大兄弟你很活跃啊…… validation和test的数据一样都是训练过程中模型不可见的,之所以区分validation和test,主要是不允许面向validation数据进行训练。 在这里test指的就是validation,建议学习一下training set, validation set和test set的区别与使用方法。

MoyanZitto avatar Oct 11 '16 07:10 MoyanZitto

@MoyanZitto .......我知道这几个数据集的区别,只是这里有误导..... 不过我担心随着迭代次数增加模型会不会逐渐开始过度拟合validation data???

dorbodwolf avatar Oct 11 '16 07:10 dorbodwolf

@dorbodwolf 不会,validation data的过拟合是你通过调超参数造成的,单纯的训练不可能对validation过拟合

MoyanZitto avatar Oct 11 '16 08:10 MoyanZitto