Say one-hot encoding is the perfect way to represent a series of objects such as clothing items. Ie: A hat is [1 0 0], a tie is [0 1 0].

I want to predict what a customer buys if they spend a certain amount of money, which will serve as an input to the NN. Eg: For one example, the customer spends $22. The thing is, the customer may buy multiples of the same clothing item.

What would be the best way to make the neural network output something like [2 1 0] to show its prediction as 2 hats and 1 tie, given the input of $22?

As far as I understand binary crossentropy is good for multilabel problems, but nowhere could I find an example of how I could apply this when the same label occurs more than once.

The only solution I could think of was turning this into a regression problem, but doing so would seem bad since this is a categorical problem, and the network should output fixed natural numbers depending upon the number of times an object is predicted.


1 Answer 1


But your intuition about regression is right. Basically, you have multi target regression problem. Each category is a separate target. If your get float output as prediction, you can round it. Float output also makes sense, because it shows you how confident is your model about prediction and the expectation of the number of bought items.

Number of bought items is structured as ordinals, so it makes sense to predict it as multi target regression. Moreover, you may not know the upper limit of the number of bought items, so it makes no sense to predict number of items as categories.

Look at this for reference:

  1. Neural Network for Multiple Output Regression
  2. Resources for learning about multiple-target techniques?
  • $\begingroup$ That makes sense come to think of it, thanks $\endgroup$
    – user4779
    Commented Apr 19, 2019 at 4:27
  • $\begingroup$ What would be the best way to implement this? I read the links and it seems a final dense layer with no activation would be ideal whilst using a MSE loss? Ie: If I have 8 classes, I could do something like.. y_classes = 8, .... model.add(Dense(y_classes,Activation=None) for the output layer? $\endgroup$
    – user4779
    Commented Apr 19, 2019 at 18:56
  • 1
    $\begingroup$ You just can either not to specify activation or use 'linear' activation $\endgroup$ Commented Apr 21, 2019 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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