Metric/loss for bin classification I have a model that has to classify inputs into one of 45 categories but those categories actually represent bins (e.g. bins 1, 2 and 3 are between 1 and 10, 11 and 20, 21 and 30 respectively). What I would like is my model to classify properly values into bins but I am not too upset if it puts 19 into bin #3 even in bin #1. What is the loss function that would measure distance from the correct category and will score the classification in neighbouring bins with weight of say 1/n where n is the distance to the correct bin.

mind you that what I am looking for is different from the top_k metric that keras has.
It looks like you should redefine your task as a regression problem instead of a classification problem, because your target variable is numerical. 

The performance will be much better and it will avoid the need for a questionable pseudo-regression-like measure. Mean absolute error and mean squared error are standard regression evaluation measures.