简体   繁体   English

什么是训练准确率和训练损失以及为什么我们需要计算它们?

[英]What is training accuracy and training loss and why we need to compute them?

I am new to Lstm and machine learning and I am trying to understand some of it's concepts.我是 Lstm 和机器学习的新手,我想了解它的一些概念。 Below is the code of my Lstm model.下面是我的 Lstm model 的代码。

Lstm model: LSTM model:

model = Sequential()
model.add(Embedding(vocab_size, 50, input_length=max_length-1))
model.add(LSTM(50))
model.add(Dropout(0.1))
model.add(Dense(vocab_size, activation='softmax'))

early_stopping = EarlyStopping(monitor='val_loss', patience=42)                                                                                                            
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
history = model.fit(X, y, validation_split=0.2, epochs=500, verbose=2,batch_size = 20)

Below is a sample of my output:下面是我的 output 的示例:

在此处输入图像描述

And the train/test accuracy and train/test loss diagrams:以及训练/测试精度和训练/测试损失图: 在此处输入图像描述

My undersanding (and please correct me if I am wrong) is that val_loss and val_accuracy is the loss and accuracy of the test data.我的理解(如果我错了请纠正我)是 val_loss 和 val_accuracy 是测试数据的损失和准确性。 My question is, what is the train accuracy and train loss and how these values are computed?.我的问题是,什么是列车精度和列车损失以及如何计算这些值? Thank you.谢谢你。

1. loss and val_loss- 1. loss 和 val_loss-

In deep learning, the loss is the value that a neural.network is trying to minimize.在深度学习中, loss是神经网络试图最小化的值。 That is how a neural.network learns by adjusting weights and biases in a manner that reduces the loss.这就是神经网络如何通过以减少损失的方式调整权重和偏差来学习。

loss and val_loss differ because the former is applied to the train set , and the latter to the test set . lossval_loss不同,因为前者应用于train set ,而后者应用于test set As such, the latter is a good indication of how the model performs on unseen data.因此,后者很好地表明了 model 如何处理看不见的数据。

2. accuracy and val_accuracy- 2. accuracy 和 val_accuracy-

Once again, acc is on the training data , and val_acc is on the validation data .再一次, acctraining data上, val_accvalidation data上。 It's best to rely on val_acc for a fair representation of model performance because a good neural.network will end up fitting the training data at 100%, but would perform poorly on unseen data.最好依靠val_acc来公平表示 model 性能,因为良好的神经网络最终将以 100% 的速度拟合训练数据,但在未见过的数据上表现不佳。

Training should be stopped when val_acc stops increasing, otherwise your model will probably overffit.val_acc停止增加时应该停止训练,否则你的 model 可能会过载。 You can use earlystopping callback to stop training.您可以使用 earlystopping 回调来停止训练。

3. Why do we need train accuracy and loss? 3. 为什么我们需要train accuracy和loss?

It's not a meaningful evaluation metric because a neural.network with sufficient parameters can essentially memorize the labels of training data and then perform no better than random guessing on previously unseen examples.这不是一个有意义的评估指标,因为具有足够参数的神经网络基本上可以记住训练数据的标签,然后对以前看不见的例子进行随机猜测。

However, it can be useful to monitor the accuracy and loss at some fixed interval during training as it may indicate whether the backend is functioning as expected and if the training process needs to be stopped.但是,在训练期间以某个固定间隔监视accuracyloss可能很有用,因为它可以指示后端是否按预期运行以及是否需要停止训练过程。

Refer here for a detailed explanation about earlystopping.有关提前停止的详细说明,请参阅此处

4. How accuracy and loss are calculated? 4.accuracy和loss是怎么计算的?

Loss and accuracy are calculated as you train, according to the loss and metrics specified in compiling the model. Before you train, you must compile your model to configure the learning process.根据编译 model 时指定的损失和指标,在训练时计算损失和准确度。在训练之前,您必须编译 model 以配置学习过程。 This allows you to specify the optimizer , loss function , and metrics , which in turn are how the model fit function knows what loss function to use, what metrics to keep track of, etc.这允许您指定optimizerloss functionmetrics ,这反过来又是 model 如何拟合 function 知道要使用什么损失 function,要跟踪什么指标等。

The loss function (like binary cross entropy) documentation can be found here and the metrics (like accuracy ) documentation can be found here . loss function(如二进制交叉熵)文档可在此处找到,指标(如accuracy )文档可在此处找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM