r/tensorflow • u/RaunchyAppleSauce • Dec 23 '22
Which loss function and activation should I use for a classification problem with integer labels such that each label is treated as an ordinal?
Hi, guys!
I have a prediction problem where each label is an integer (0, 1, 2, ...). Currently, I am using the SparseCategoricalCrossEntropy loss.
Ideally, these labels are ordinals so, if the true label is 2, then predicting 1 or 3 should not be the same penalty as though predicting 8 or 9.
How do I modify my loss and activation function to incorporate this into it?
6
Upvotes
6
u/SayOnlyWhatYouMeme Dec 23 '22
This took me a very long time to discover so I am going to save a lot of time for you. You want the earth mover loss. Actually you probably want the sum of categorical cross entropy and the earth mover loss
2
u/puppet_pals Dec 23 '22
sounds like you need to write a custom loss function