为什么标准化后新值大于1和-1?

时间:2019-05-07 14:25:39

标签: python-3.x machine-learning standardized

我想将数据归一化为零均值和1个标准差,但最终结果仍然具有大于1和-1的值,为什么?

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]

1 个答案:

答案 0 :(得分:0)

有几种不同的标准化数据的方法,可用于不同的目的和方法。您在此处选择的那个(零均值和单位标准偏差)确实有效,但绝不意味着将归一化的数据限制为[-1, 1];您所获得的确实是您的新数据的均值和单位SD为零,即完全您所要求的:

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

例如,如果您希望归一化的数据位于[0, 1]中,则应使用其他归一化方法(最小-最大):

# 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.        ])