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 eac
Answering your questions:
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.
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.
loss
and val_loss
?In deep learning, the loss is the value that a neural network is trying to minimize. That is how a neural network learns—by adjusting weights and biases in a manner that reduces the loss.
For instance, in regression tasks, you have a continuous target, e.g., height. What you want to minimize is the difference between your predictions, and the actual height. You can use mean_absolute_error
as loss so the neural network knows this what it needs to minimize.
In classification, it's a little more complicated, but very similar. Predicted classes are based on probability. The loss is therefore also based on probability. In classification, the neural network minimizes the likelihood to assign a low probability to the actual class. The loss is typically categorical_crossentropy
.
loss
and val_loss
differ because the former is applied to the train set, and the latter the test set. As such, the latter is a good indication of how the model performs on unseen data. You can get a validation set by using validation_data=[x_test, y_test]
or validation_split=0.5
.
It's best to rely on the val_loss
to prevent overfitting. Overfitting is when the model fits the training data too closely, and the loss
keeps decreasing while the val_loss
is stale, or increases.
In Keras, you can use EarlyStopping
to stop training when the val_loss
stops decreasing. Read here.
Read more about deep learning losses here: Loss and Loss Functions for Training Deep Learning Neural Networks.
acc
and val_acc
?Accuracy is a metric only for classification. It gives the percentage of instances that are correctly classified.
Once again, acc
is on the training data, and val_acc
is on the validation 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.