3
$\begingroup$

I have an LSTM model in Keras for categorical classification (20 possible categories). In many cases, my data can fit multiple categories.

Obviously, my current model uses one-hot encoding and fits on that - that gives me accuracy and validation rates in the 50-60% but I want to improve that by comparing how the model does against the top 3 categories that the algorithm chooses.

Right now, I use Keras with categorical_crossentropy. I presume that this checks to see if the label is the top match and bases the accuracy on that matching. How can I modify the fit/training of the model to allow the labeled category to be in the top 3 (or top X-number) of matches for the accuracy score?

$\endgroup$
  • 2
    $\begingroup$ Are you talking about multi-label categorical classification then? If yes this will change how you think. $\endgroup$ – TwinPenguins Oct 31 '18 at 7:19
0
$\begingroup$

If you're doing multilabel, you should do binary-crossentropy and sigmoid in a final layer. You must score your labels separately. Here's an example.

| improve this answer | |
$\endgroup$
0
$\begingroup$

You are looking for top-k categorical accuracy. This is actually implemented in keras, but you might want to change the k, which can be done with partial function. This is the related link.

| improve this answer | |
$\endgroup$

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.