46
$\begingroup$

I am currently training a neural network and I cannot decide which to use to implement my Early Stopping criteria: validation loss or a metrics like accuracy/f1score/auc/whatever calculated on the validation set.

In my research, I came upon articles defending both standpoints. Keras seems to default to the validation loss but I have also come across convincing answers for the opposite approach (e.g. here).

Anyone has directions on when to use preferably the validation loss and when to use a specific metric?

$\endgroup$

4 Answers 4

36
$\begingroup$

TLDR; Monitor the loss rather than the accuracy

I will answer my own question since I think that the answers received missed the point and someone might have the same problem one day.

First, let me quickly clarify that using early stopping is perfectly normal when training neural networks (see the relevant sections in Goodfellow et al's Deep Learning book, most DL papers, and the documentation for keras' EarlyStopping callback).

Now, regarding the quantity to monitor: prefer the loss to the accuracy. Why? The loss quantify how certain the model is about a prediction (basically having a value close to 1 in the right class and close to 0 in the other classes). The accuracy merely account for the number of correct predictions. Similarly, any metrics using hard predictions rather than probabilities have the same problem.

Obviously, whatever metrics you end up choosing, it has to be calculated on a validation set and not a training set (otherwise, you are completely missing the point of using EarlyStopping in the first place)

$\endgroup$
2
  • $\begingroup$ @qmeeus sorry if I am missing your point, but why is loss better than accuracy? We want to do well on the accuracy at "test time" so I'd personally track the accuracy not the loss. The loss is usually a made up quantity that upper bounds what we really want to do (convex surrogate functions). $\endgroup$ Mar 4, 2021 at 17:53
  • 2
    $\begingroup$ @CharlieParker, accuracy is rarely what you want (problem with class imbalance, etc.) but even ignoring this problem, a model that predicts each example correctly with a large confidence is preferable to a model that predicts each example correctly with a 51% confidence. The accuracy being a discrete transformation of the class probabilities, it does not allow you to make this distinction. Cross-entropy does. It does not impact the error rate on out of distribution samples but what does anyway? ;) $\endgroup$
    – qmeeus
    Mar 5, 2021 at 9:16
6
$\begingroup$

In my opinion, this is subjective and problem specific. You should use whatever is the most important factor in your mind as the driving metric, as this might make your decisions on how to alter the model better focussed.

Most metrics one can compute will be correlated/similar in many ways: e.g. if you use MSE for your loss, then recording MAPE (mean average percentage error) or simple $L_1$ loss, they will give you comparable loss curves.

For example, if you will report an F1-score in your report/to your boss etc. (and assuming that is what they really care about), then using that metric could make most sense. The F1-score, for example, takes precision and recall into account i.e. it describes the relationship between two more fine-grained metrics.

Bringing those things together, computing scores other than normal loss may be nice for the overview and to see how your final metric is optimised over the course of the training iterations. That relationship could perhaps give you a deeper insight into the problem,

It is usually best to try several options, however, as optimising for the validation loss may allow training to run for longer, which eventually may also produce a superior F1-score. Precision and recall might sway around some local minima, producing an almost static F1-score - so you would stop training. If you had been optimising for pure loss, you might have recorded enough fluctuation in loss to allow you to train for longer.

$\endgroup$
0
1
$\begingroup$

Usually a loss function is just a surrogate one because we cannot optimize directly the metric. If the metric is representative of the task(business value the best), the value of the metric on evaluation dataset would be better than the loss on that dataset. For instance, if data imbalance is a serious problem, try PR curve.

$\endgroup$
-1
$\begingroup$

I am currently training a neural network and I cannot decide which to use to implement my Early Stopping criteria: validation loss or a metrics like accuracy/f1score/auc/whatever calculated on the validation set.

If you are training a deep network, I highly recommend you not to use early stop. In deep learning, it is not very customary. Instead, you can employ other techniques like drop out for generalizing well. If you insist on that, choosing criterion depends on your task. If you have unbalanced data, you have to employ F1 score and evaluate it on your cross-validation data. If you have balanced data, try to use accuracy on your cross-validation data. Other techniques highly depend on your task.

I highly encourage you to find a model which fits your data very well and employ drop out after that. This is the most customary thing people use for deep models.

$\endgroup$
12
  • 4
    $\begingroup$ I am using dropout as well. However, I can't find a reason why early stopping should not be used though... $\endgroup$
    – qmeeus
    Aug 21, 2018 at 19:21
  • $\begingroup$ Early stop tries to solve both learning and generalization problems. On the other hand drop out just tries to overcome the generalization problem. $\endgroup$ Aug 21, 2018 at 19:35
  • 2
    $\begingroup$ You don't answer my question... I don't deny the fact that dropout is useful and should be used to protect against overfitting, I couldn't agree more on that. My question is: why do you say that early stop should not be used with ANN? (cf your first sentence: If you are training a deep network, I highly recommend you not to use early stop.) $\endgroup$
    – qmeeus
    Aug 21, 2018 at 20:22
  • $\begingroup$ Did you read my last comment? It exactly answers your question. It's a famous quote from pr. Ng in his deep learning class, second course. The latter case is an easier task due to not struggling to solve multple tasks simoltaneously. $\endgroup$ Aug 21, 2018 at 21:43
  • 3
    $\begingroup$ And in order to find it and find the right set of hyperparameters, I'm employing some kind of directed grid search with early stop for the reasons I explained above. Point taken though and once I have selected the final model and I will train it, I will not use early stop. Thank you for this interesting discussion and for you advice $\endgroup$
    – qmeeus
    Aug 22, 2018 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.