Reputation: 318
Once you do normalisation of your data so the values are between 0-1, how do you de-normalise it so you can interpret the result?
So when you normalise your data, and feed it to your network and get an output which is normalised data. How do you reverse normalisation to get the original data?
Upvotes: 13
Views: 14070
Reputation: 477
Additionally since the question is tagged with keras, if you were to normalize the data using its builtin normalization layer, you can also de-normalize it with a normalization layer.
You need to set the invert parameter to True, and use the mean and variance from the original layer, or adapt it to the same data.
# Create a variable for demonstration purposes
test_var = pd.Series([2.5, 4.5, 17.5, 10.5], name='test_var')
#Create a normalization layer and adapt it to the data
normalizer_layer = tf.keras.layers.Normalization(axis=-1)
normalizer_layer.adapt(test_var)
#Create a denormalization layer using the mean and variance from the original layer
denormalizer_layer = tf.keras.layers.Normalization(axis=-1, mean=normalizer_layer.mean, variance=normalizer_layer.variance, invert=True)
#Or create a denormalization layer and adapt it to the same data
#denormalizer_layer = tf.keras.layers.Normalization(invert=True)
#denormalizer_layer.adapt(test_var)
#Normalize and denormalize the example variable
normalized_data = normalizer_layer(test_var)
denormalized_data = denormalizer_layer(normalized_data)
#Show the results
print("test_var")
print(test_var)
print("normalized test_var")
print(normalized_data)
print("denormalized test_var")
print(denormalized_data)
see more: https://www.tensorflow.org/api_docs/python/tf/keras/layers/Normalization
Upvotes: 2
Reputation: 10759
If you have some data d
that you normalize to 0-1 by doing (something like)
min_d = np.min(d)
max_d = np.max(d)
normalized_d = (d - min_d) / (max_d - min_d)
you can de-normalize this by inverting the normalization. In this case
denormalized_d = normalized_d * (max_d - min_d) + min_d
Upvotes: 22