机器学习归一化的几种方法

数据归一化的两个好处:

1、提升模型的收敛速度
2、提升模型的精度

机器学习常见的归一化算法 :

1、 min-max 标准化(Min-max normalization)

也叫0-1标准化(0-1 normalization):对原始数据的线性变换,是结果落到[0,1]区间,转换函数如下:

(63) x n o r m a l i z a t i o n = x m i n m a x m i n

转换代码如下:

def NormalData(x):
    return[(float(i)-min(x))/float(max(x)-min(x)) i for i in x]

如果想要把数据映射到[-1,1],则公式将换成:

(28) x n o r m a l i z a t i o n = x x m e a n x m a x x m i n

转换函数如下:

import numpy as np
def NormalData(x):
    return[(float(i)-np.mean(x))/float(max(x)-min(x)) i for i in x]

这种归一化方法的缺点是:当有新数据加入时,可能导致max和min的变化,需要重新计算。

2、z-score 标准化(zero-mean normalization):也叫标准差标准化

公式如下:

(75) x n o r m a l i z a t i o n = x μ σ

z-score标准化方法适用于训练集的最大值和最小值未知的情况下。或有异常数据的情况下。
x-μ只改变均值,标准差不变,所以均值变为0
(x-μ)/σ只会使标准差除以σ倍,所以标准差变为1

参考网址:http://blog.csdn.net/pipisorry/article/details/52247379

猜你喜欢

转载自blog.csdn.net/xiongchengluo1129/article/details/79156032