1 minute read

1. ScalingPermalink

这个简单,scaling 一般指 xcx 或者 xxc 的变形。

2. StandardizationPermalink

使数据符合 standard normal distribution XN(μ=0,σ2=1) 的变形,它包含两步:

  1. centering: xxmean(x)
  2. scaling by standard deviation: xxstd(x)

注意:

  • μmean(x)
  • σ2 是 variance var(x)
  • σ 是 standard deviation (也叫 unit variance) std(x)

所以合起来就是:xxmean(x)std(x)

另外,对单个的 scalar xi 而言,ximean(x)std(x) 称为 xiz-score

3. NormalizationPermalink

3.1 NormPermalink

Quote from Wikipedia: Norm (mathematics):

Given a vector space V over a subfield F of the complex numbers, a norm on V is a nonnegative-valued scalar function p:V[0,+) with the following properties:

cF,u,vV,

  1. p(u+v)p(u)+p(v)
  2. p(cv)=|c|p(v)
  3. If p(v)=0 then v=0 is the zero vector.

常见的 norm 有:

  • L1 norm:x1=i=1n|xi|
  • L2 norm:x2=i=1nxi2
  • max norm:x=max(|x1|,,|xn|)

3.2 Normalization Scenario 1: AlgebraPermalink

我们常说 “把一个 vector normalize 成一个 unit vector”,这其实是一个 vvv? 的变形 (即把向量除以它自身的 norm)。

我们可以看到:

  • vv11=1
  • vv22=1
  • vv=1

我们经常可以看到 “normalization 把数据压缩到 [0,1] 区间内” 或者类似的说法,我觉得这可能来源于 “unit vector 的 norm 为 1” 这件事,但是要注意的是:

  • unit vector 的 norm 为 1,只能说明各项 xi 的绝对值是在 [0,1] 区间内

3.3 Normalization Scenario 2: StatisticsPermalink

在统计学上说 normalization,那意思就海了去了。从 Normalization (statistics) 来看:

  • standardization 是一种 normalization
  • studentization 是一种 normalization
  • min-max scaling 也是一种 normalization (而且它不符合我们的 scaling 定义)

3.4 The Problems with NormalizationPermalink

我觉得统计学上 normalization 定义的最大的问题是:我看不到这些变形与 norm 的关系。

然后随之而来的第二个问题:我怎么知道你说的 normalization 是 algebra 的还是 statistics 的?

比如 sklearn.preprocessing.normalize,我一直以为它做的是 standardization,但其实不是!

  • sklearn 的 standardization 要用 sklearn.preprocessing.StandardScaler

它做的其实是 vector normalization,但是它的 max norm 又不是标准的:

......:
    ......:
        # https://github.com/scikit-learn/scikit-learn/blob/bac89c2/sklearn/preprocessing/data.py#L1564
        if norm == 'l1':
            norms = np.abs(X).sum(axis=1)
        elif norm == 'l2':
            norms = row_norms(X)
        elif norm == 'max':
            norms = np.max(X, axis=1)  # You call this max norm???
        norms = _handle_zeros_in_scale(norms, copy=False)
        X /= norms[:, np.newaxis]

对于第二个问题,一个简单点的判别方法是:你看到 L1L2 这些字眼时,那必定是 algebra 的 normalization。但是事情发展成这样,才是最值得吐槽的。

Categories:

Updated:

Comments