3

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?

Pluviophile
  • 3,520
  • 11
  • 29
  • 49
I_Play_With_Data
  • 2,079
  • 2
  • 16
  • 39

2 Answers2

1

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.

Yohanes Alfredo
  • 1,113
  • 6
  • 15
0

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.

Piotr Rarus
  • 814
  • 4
  • 15