机器学习中为什么要做归一化normalization

我们处理feature的时候往往先要normalize encoding,使用python可以很容易做:

from sklearn import preprocessing
from scipy.stats import rankdata

x = [[1], [3], [34], [21], [10], [12]]
std_x = preprocessing.StandardScaler().fit_transform(x)
norm_x= preprocessing.MinMaxScaler().fit_transform(x)
norm_x2= preprocessing.LabelEncoder().fit_transform(x)

print('std_x=\n', std_x)
print('norm_x=\n', norm_x)
print('norm_2=\n', norm_x2)

print('oringial order =', rankdata(x))
print('stand order    =', rankdata(std_x))
print('normalize order=', rankdata(norm_x))

其中preprocessing.LabelEncoder().fit_transform(x)就是做normalize encoding,上面的程序输入如下:

std_x=
 [[-1.1124854 ]
 [-0.93448773]
 [ 1.82447605]
 [ 0.66749124]
 [-0.31149591]
 [-0.13349825]]
norm_x=
 [[0.        ]
 [0.06060606]
 [1.        ]
 [0.60606061]
 [0.27272727]
 [0.33333333]]
norm_2=
 [0 1 5 4 2 3]
oringial order = [1. 2. 6. 5. 3. 4.]
stand order    = [1. 2. 6. 5. 3. 4.]
normalize order= [1. 2. 6. 5. 3. 4.]

可以看到normailize之后的结果是 [0 1 5 4 2 3]。这样做的好处是什么呢?

下面图片转自知乎(https://www.zhihu.com/questio...

图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值