如何在Keras模型拟合中了解损失acc val_loss val_acc [英] How to understand loss acc val_loss val_acc in Keras model fitting

查看:142
本文介绍了如何在Keras模型拟合中了解损失acc val_loss val_acc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Keras的新手,并且对如何理解我的模型结果有一些疑问.这是我的结果:(为方便起见,我仅将损失acc val_loss val_acc粘贴到此处的每个纪元之后)

I'm new on Keras and have some questions on how to understanding my model results. Here is my result:(for your convenience, I only paste the loss acc val_loss val_acc after each epoch here)

对4160个样本进行训练,对1040个样本进行验证,如下所示:

Train on 4160 samples, validate on 1040 samples as below:

Epoch 1/20
4160/4160 - loss: 3.3455 - acc: 0.1560 - val_loss: 1.6047 - val_acc: 0.4721

Epoch 2/20
4160/4160 - loss: 1.7639 - acc: 0.4274 - val_loss: 0.7060 - val_acc: 0.8019

Epoch 3/20
4160/4160 - loss: 1.0887 - acc: 0.5978 - val_loss: 0.3707 - val_acc: 0.9087

Epoch 4/20
4160/4160 - loss: 0.7736 - acc: 0.7067 - val_loss: 0.2619 - val_acc: 0.9442

Epoch 5/20
4160/4160 - loss: 0.5784 - acc: 0.7690 - val_loss: 0.2058 - val_acc: 0.9433

Epoch 6/20
4160/4160 - loss: 0.5000 - acc: 0.8065 - val_loss: 0.1557 - val_acc: 0.9750

Epoch 7/20
4160/4160 - loss: 0.4179 - acc: 0.8296 - val_loss: 0.1523 - val_acc: 0.9606

Epoch 8/20
4160/4160 - loss: 0.3758 - acc: 0.8495 - val_loss: 0.1063 - val_acc: 0.9712

Epoch 9/20
4160/4160 - loss: 0.3202 - acc: 0.8740 - val_loss: 0.1019 - val_acc: 0.9798

Epoch 10/20
4160/4160 - loss: 0.3028 - acc: 0.8788 - val_loss: 0.1074 - val_acc: 0.9644

Epoch 11/20
4160/4160 - loss: 0.2696 - acc: 0.8923 - val_loss: 0.0581 - val_acc: 0.9856

Epoch 12/20
4160/4160 - loss: 0.2738 - acc: 0.8894 - val_loss: 0.0713 - val_acc: 0.9837

Epoch 13/20
4160/4160 - loss: 0.2609 - acc: 0.8913 - val_loss: 0.0679 - val_acc: 0.9740

Epoch 14/20
4160/4160 - loss: 0.2556 - acc: 0.9022 - val_loss: 0.0599 - val_acc: 0.9769

Epoch 15/20
4160/4160 - loss: 0.2384 - acc: 0.9053 - val_loss: 0.0560 - val_acc: 0.9846

Epoch 16/20
4160/4160 - loss: 0.2305 - acc: 0.9079 - val_loss: 0.0502 - val_acc: 0.9865

Epoch 17/20
4160/4160 - loss: 0.2145 - acc: 0.9185 - val_loss: 0.0461 - val_acc: 0.9913

Epoch 18/20
4160/4160 - loss: 0.2046 - acc: 0.9183 - val_loss: 0.0524 - val_acc: 0.9750

Epoch 19/20
4160/4160 - loss: 0.2055 - acc: 0.9120 - val_loss: 0.0440 - val_acc: 0.9885

Epoch 20/20
4160/4160 - loss: 0.1890 - acc: 0.9236 - val_loss: 0.0501 - val_acc: 0.9827

这是我的理解:

  1. 两个损失(损失和val_loss)都在减少,而牵引acc(acc和val_acc)却在增加.因此,这表明建模是经过良好训练的.

  1. The two losses (both loss and val_loss) are decreasing and the tow acc (acc and val_acc) are increasing. So this indicates the modeling is trained in a good way.

val_acc是模型预测的良好程度的度量.因此,对于我来说,看起来该模型在经过6个时间段后就训练得很好,而其余的训练则没有必要.

The val_acc is the measure of how good the predictions of your model are. So for my case, it looks like the model was trained pretty well after 6 epochs, and the rest training is not necessary.

我的问题是:

  1. acc(训练集上的acc)始终小于val_acc,实际上要小得多.这正常吗?为什么会发生这种情况?在我看来,acc通常应该比val_acc更好.

  1. The acc (the acc on training set) is always smaller, actually much smaller, than val_acc. Is this normal? Why this happens?In my mind, acc should usually similar to better than val_acc.

20个纪元后,acc仍在增加.因此,我应该使用更多的时期并在acc停止增加时停止吗?还是不管acc的趋势如何,都应该在val_acc停止增加的地方停下来?

After 20 epochs, the acc is still increasing. So should I use more epochs and stop when acc stops increasing? Or I should stop where val_acc stops increasing, regardless of the trends of acc?

我的结果还有其他想法吗?

Is there any other thoughts on my results?

谢谢!

推荐答案

回答您的问题:

  1. 如官方 keras常见问题解答

训练损失是每批训练数据中损失的平均值.由于您的模型会随着时间而变化,因此前几个时期的损失通常要比最后几个时期的损失高.另一方面,一个时期的测试损失是使用模型计算的,因为它处于该时期的末尾,因此损失较低.

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.

  1. 当val_acc停止增加时,应该停止训练,否则您的模型可能会过拟合.您可以使用Earlystopping回调来停止训练.

  1. Training should be stopped when val_acc stops increasing, otherwise your model will probably overffit. You can use earlystopping callback to stop training.

您的模型似乎取得了很好的结果.保持良好的工作.

Your model seems to achieve very good results. Keep up the good work.

这篇关于如何在Keras模型拟合中了解损失acc val_loss val_acc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆