I want to normalize data to zero mean and 1 standard deviation But my final result still has values greater than 1 and -1,Why?
E2 = np.array([-2.51212507515, -2.19475817821, -1.46734920106,
-1.21180880012, -1.00548224796, -0.659646985536, -0.295605554552,
-0.110606689781,-0.0470815913269, 0.200749107619, 0.679857411839,
0.850614581975,1.15145662114, 1.48124693613, 2.09076285542,
3.04977680958])
Sum_E2 = np.mean(E2)
print(Sum_E2)
sigma_2 = np.std(E2,ddof=1)
print("sigma is: ", sigma_2)
print((E2-Sum_E2)/sigma_2)
#result:
[-1.6512918, -1.44267744, -0.96453068, -0.79655665, -0.66093229,
-0.43360487,-0.19431, -0.07270495 -0.03094808, 0.13195814,
0.44688976, 0.55913334,0.75688543, 0.97366606, 1.37431834, 2.00470569]
There are several different ways of normalizing data, serving different purposes and approaches. The one you have chosen here (zero mean & unit standard deviation) is indeed valid, but in no way means that the normalized data will be confined to [-1, 1]; what you have achieved is indeed your new data to have zero mean & unit SD, i.e. exactly what you have asked for:
import numpy as np
# your normalized data
x_norm1 = np.array ([-1.6512918, -1.44267744, -0.96453068, -0.79655665, -0.66093229,
-0.43360487,-0.19431, -0.07270495 -0.03094808, 0.13195814,
0.44688976, 0.55913334,0.75688543, 0.97366606, 1.37431834, 2.00470569])
np.mean(x_norm1)
# 2.9605947323337507e-17
# this mean is practically zero:
np.isclose(np.mean(x_norm1),0)
# True
np.std(x_norm1)
# 1.000149995079366
If you want, say, your normalized data to lie in [0, 1], you should use a different normalization method (min-max):
# your initial data:
x = np.array([-2.51212507515, -2.19475817821, -1.46734920106,
-1.21180880012, -1.00548224796, -0.659646985536, -0.295605554552,
-0.110606689781, -0.0470815913269, 0.200749107619, 0.679857411839,
0.850614581975,1.15145662114, 1.48124693613, 2.09076285542,
3.04977680958])
x_norm2 = (x-np.min(x))/(np.max(x)-np.min(x))
x_norm2
# result:
array([ 0. , 0.05706086, 0.18784507, 0.23378986, 0.27088626,
0.33306558, 0.39851827, 0.43178007, 0.44320154, 0.48776017,
0.57390126, 0.60460248, 0.65869226, 0.71798678, 0.82757446, 1. ])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With