gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:15:55 29 4
gpt4 key购买 nike

我想将数据标准化为零均值和 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, 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. ])

关于python - 为什么标准化后新值大于 1 和 -1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56024816/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com