# How to make a neural network output a specific number out of a certain range?

I have a neural network with an Input layer, 2 hidden Dense layers and an Output layer.

I would like for each neuron in the Output layer to give me a number between 0 and 2 (either 0, 1 or 2), like so:

If I use a neuron for each possibility (a neuron for 0, a neuron for 1 and another for 2) and then pick the one with the best prediction, the output layer length would be far too much.

Is there a way to implement this ? (I am fairly new to neural networks and the like)

There are two ways to do that:

1. Scale your output data from [0, 2] to [0, 1] and apply Sigmoid activation at the end.

2. Make your own custom activation function that output everything in [0, 2]

I strongly suggest you no. 1, it's way faster to implement.

• Thank you so much for your answer :) Could you kindly provide me with an example implementation (tutorial or the like) of such approach (approach number 1 or 2 or both)
– Ness
Apr 8 at 14:04
• I think you don't need a whole tutorial, just apply a basic Min-Max scaler on your Y data to implement method 1. If your Y data already is in [0, 2] then just do: y = y/2 to get it in [0,1]. Alternatively, lots of people use sklearn's MinMaxScaler. Apr 8 at 14:11
• Alrighty then, thank you so much :)
– Ness
Apr 8 at 14:11
• NP, remember to scale the data back one you're done training! :) Apr 8 at 14:28
• But doesn't this look like a classification problem ? The suggested solution seems to convert it into a regression. Apr 8 at 16:34