此内容在sklearn官网地址: http://scikit-learn.org/stable/modules/preprocessing.html#
sklearn版本:0.18.2
Standardization 标准化
Normalization 正则化
是否需要进行数据标准化?
一般涉及到梯度下降和距离的计算需要进行标准化或正则化。例如Logistic Regression、SVM、PCA等。
很多博客中将标准化和正则化归为同一种处理方式,实际上他们是不同的情况,标准化针对的是把整列(特征)作为处理对象,而正则化把行(样本)作为处理对象,而且他们处理的公式方法也不同。
标准化(Standardization)
Standardization of datasets is a common requirement for many machine learning estimators implemented in scikit-learn; they might behave badly if the individual features do not more or less look like standard normally distributed data: Gaussian with zero mean and unit variance. ——scikit-learn.org
标准化是常用的机器学习特征处理的方法,它可以将一列数据的平均值变为0,方差变为1 。但是不改变原来的数据结构分布,只是将数值进行了缩放。使得所有特征在同一量纲下进行数据处理,避免有些特征整体偏大对整体处理造成偏差。
z-score 方法
μ \mu μ 是平均值, σ \sigma σ 是标准差。
得到的结果是,对于每个特征(每列),他们的平均值为0,方差为1。
正则化/归一化(Normalization)
Normalization is the process of scaling individual samples to have unit norm. This process can be useful if you plan to use a quadratic form such as the dot-product or any other kernel to quantify the similarity of any pair of samples. ——scikit-learn.org
正则化针对的是每行,或者说每个样本的不同特征。一般计算样本之间距离时使用其做归一化处理,比如聚类,K近邻、文本分类。
正则化的过程是将每个样本缩放到单位范数(每个样本的范数为1),如果后面要使用如二次型(点积)或者其它核方法计算两个样本之间的相似性这个方法会很有用。
Normalization主要思想是对每个样本计算其p-范数,然后对该样本中每个元素除以该范数,这样处理的结果是使得每个处理后样本的p-范数(L1,L2)等于1。
p-范数的计算公式: