Reputation: 842
I would like to normalize the labels for my neural network but also be able to reverse the normalization process, so that I can scale my prediction outputs back to the original size.
My labels are of the form:
[[ 2.25, 2345123.23],
[ 1.13, 234565.11],
...
[0.12, 990232.98]]
Now I would like to normalize each column such that the values range from 0 to 1.
I found that pytorch has the torch.nn.functional.normalize function which allows me to normalize along a specific dimension using whichever p-norm I desire.
Is there an existing inverse function that allows me to scale my normalized values?
Currently, I am using a custom function that performs feature scaling as follows which scales both columns together, however, I wanted to make sure I am not creating a function that already exists in the torch library before rewriting it.
A = lbl_min
B = lbl_max
a = lower_bound
b = upper_bound
self.labels = a*np.ones(shape) + (self.labels - A*np.ones(shape))*(b-a)/(B-A)
Additional information: I am using a regression model to output continuous real world values. I need to "denormalize" my predictions in order to validate them against the true values. Also, if I were to use my model in a practical application, I would need my output back in its original units.
Upvotes: 1
Views: 11667
Reputation: 46479
This is a trick question right. It has no sense to denormalize your values.
Why? Because once you normalize them, the neural net should learn to create the predictions based on your normalized values.
So you are safe.
BTW, you will typically use mean and std of your data to normalize.
In case of the regression problems it is the same. At least the architectures I created so far. For instance: Create the model M1 to learn sum +
operation.
You provide pair of values a,b
and you set the sum c
as prediction.
In case you train another model M2 with a/10, b/10
and you again provide the c
as prediction, this means you normalize the input.
All you have to do in the inference phase is to normalize your inputs (divide by 10) and you get the correct output.
Upvotes: -1