6
$\begingroup$

I have two Machine Learning models (I use LSTM) that have a different result on the validation set (~100 samples data):

  • Model A: Accuracy: ~91%, Loss: ~0.01
  • Model B: Accuracy: ~83%, Loss: ~0.003

The size and the speed of both model are almost the same. So, which model should I choose?

$\endgroup$
  • 1
    $\begingroup$ Interesting question, I have also faced the same situation....But then it turned out it was a local minimum when I did some hyperparameter adjustments $\endgroup$ – DuttaA Feb 7 at 7:37
  • $\begingroup$ The last question is not clear, please clarify. $\endgroup$ – ssegvic Feb 15 at 10:31
3
$\begingroup$

You should note that both your results are consistent with a "true" probability of 87% accuracy, and your measurement of a difference between these models is not statistically significant. With an 87% accuracy applied at random, then there is approx 14% chance of getting the two extremes of accuracy you have observed by chance if samples are chosen randomly from the target population, and models are different enough make errors effectively at random. This last assertion is usually not true though, so you can relax a little - that is, unless you took different random slices for cross-validation in each case.

100 test cases is not really enough to discern small differences between models. I would suggest using k-fold cross-validation in order to reduce errors in your accuracy and loss estimates.

Also, it is critical to check that the cross-validation split was identical in both cases here. If you have used auto-splitting with a standard tool and not set the appropriate RNG seed, then you may have got a different set each time, and your results are just showing you variance due to the validation split which could completely swamp any differences between the models.

However, assuming the exact same dataset was used each time, and it was representative sample of your target population, then on average you should expect the one with the best metric to have the highest chance of being the best model.

What you should really do is decide which metric to base the choice on in advance of the experiment. The metric should match some business goal for the model.

Now you are trying to choose after the fact, you should go back to the reason you created the model in the first place and see if you can identify the correct metric. It might not be either accuracy or loss.

$\endgroup$
  • $\begingroup$ Agreed. More information is actually required to come at a conclusion. $\endgroup$ – DuttaA Feb 16 at 13:49
  • $\begingroup$ thank you! it's a nice Idea to use K-Fold CV. I use my model for industrial case, it's a text classification case. Some people said choose the smallest loss because high accuracy can lead to overfitting in the future, is that always true? $\endgroup$ – malioboro Feb 18 at 14:45
  • $\begingroup$ @malioboro: I don't think that is true. Without any theory to back it up, it is an empty statement in any case. I could equally say "choose the highest accuracy, because low loss can lead to overfitting in future". What do your "some people" say about that - i.e. what is their theory, and under what assumptions does it work? Either way, ignore them and choose the correct metric for your problem as suggested by its intended use. $\endgroup$ – Neil Slater Feb 18 at 14:54
  • $\begingroup$ @NeilSlater Ah.. I see.. so there aren't any theory that said lower loss is safe from overfitting. Could you please give a few examples of problem and its correct metric in your answer? I'm not pretty sure with the metric for my problem $\endgroup$ – malioboro Feb 20 at 8:53
  • $\begingroup$ Where does "You should note that both your results are consistent with a "true" probability of 87% accuracy, and your measurement of a difference between these models is not statistically significant." come from? Can you explain a little better these sentence in relation to the results presented by the OP? $\endgroup$ – nbro Feb 23 at 17:55
4
$\begingroup$

You should choose the model A. The loss is just a differentiable proxy for accuracy.

That said, the situation should be examined in more detail. If the higher loss is due to the data term, examine the data which produce high loss and check for presence of overfitting or incorrect labels.

If the higher loss is due to a regularizer then reducing the regularization factor may further improve the results.

$\endgroup$
  • $\begingroup$ What do you mean precisely by "X is a differentiable proxy for Y"? I think you should clarify this. $\endgroup$ – nbro Feb 23 at 17:51
  • 1
    $\begingroup$ It means that a differentiable function X (eg. the negative log loss) is used as a replacement (proxy) for Y (accuracy) which is unsuitable due to being non-differentiable. $\endgroup$ – ssegvic Feb 23 at 20:26
  • $\begingroup$ But if there is a "one-to-one" correspondence between accuracy and loss, then why can you obtain the results the OP is describing? $\endgroup$ – nbro Feb 23 at 20:32
  • $\begingroup$ A proxy is... ...just a proxy (an upper bound to be more precise). Not the real thing. A single datapoint may result in a very high loss contribution while only mildly affecting accuracy. One also may have high loss due to regularization term even when the accuracy is 100%. The only way to find out the reason for the discrepancy is to have a look at the data. $\endgroup$ – ssegvic Feb 23 at 21:08
1
$\begingroup$

It depends on your application! Imagine a binary classifier that is always very "confident" - it always assigns P=100% to Class A and 0% to Class B, or vice versa (sometimes wrong, never uncertain!). Now imagine a "humble" model that is perhaps fractionally less accurate, but whose probabilities are actually meaningful (when it says "Class A with probability 70%" it is wrong 30% of the time).

In your case, both losses are quite small, so we probably prefer the more accurate one.

$\endgroup$
-1
$\begingroup$

Regression: minimum error loss Classification: maximum accuracy

Thats why we optimize the error using gradient descent or other opt.

$\endgroup$
  • $\begingroup$ is there any proof for your statement? $\endgroup$ – malioboro Mar 21 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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