机器学习小数需要规范化吗
Norm is defined as a function by which we can measure the magnitude of a vector .Using norm we can measure how “large” a vector is. Norm maps a vector to non-negative value.The norm of a vector x is actually the measurement of the distance of the origin to the point x
范数定义为一个函数,通过它我们可以测量向量的大小。使用范数,我们可以测量向量的“大小”。 范数将向量映射为非负值。向量x的范数实际上是原点到点x的距离的度量
More rigorously, a norm is any func with the following properties:
更严格地说,范数是具有以下属性的任何函数:
- Norms are non-negative values.Norms are actually length or distance.So it can not be a negative number.But if a vector is zero, then norm can be zero. 范数是非负值,范数实际上是长度或距离,因此它不能是负数,但是如果向量为零,则范数可以为零。
Norms respect the triangle inequality.It just means that the norm of the sum of some vectors is less than or equal to the sum of the norms of these vectors: ||x+y||≤||x||+||y||
范数尊重三角不等式,仅表示某些矢量和的范数小于或等于这些矢量的范数的和: || x + y ||≤ || x || + || y ||
||a⋅x||=||a||⋅||x||. Here, a is a scalar and x a vector. The norm of a vector multiplied by a scalar is equal to the absolute value of this scalar multiplied by the norm of the vector.
||a⋅X || = ||一个||⋅|| X ||。 在此, a是标量, x是向量。 向量乘以标量的范数等于此标量的绝对值乘以向量的范数。
规范的应用 (Application of Norms)
- Whenever we need to calculate the loss function, we need to know the magnitude of the distance between the predicated and actual values. 每当我们需要计算损失函数时,我们都需要知道预测值与实际值之间的距离的大小。
- In regularization, we need to know the magnitude of weights. 在正则化中,我们需要知道权重的大小。
- In support-vector machine, we have to find the hyperplane that has the largest perpendicular distance between the hyperplane and the closest samples on either side. Here, we use norm to calculate these distances. 在支持向量机中,我们必须找到在超平面和任一侧最近的样本之间具有最大垂直距离的超平面。 在这里,我们使用范数来计算这些距离。
关于机器学习,规范可以分类如下: (With respect to machine learning Norms can be classified as follows-)
- Lᵖ Norm Lᵖ范数
L¹ Norm(Manhattan/Taxicab Distance)
L¹规范( 曼哈顿/出租车的距离)
- The Euclidean Norm(L² norm) 欧几里德范数(L²范数)
- The Max Norm 最大规范
- The Frobenius Norm Frobenius范数
Lᵖ范数 (Lᵖ Norm)
![Image for post](https://miro.medium.com/max/9999/1*Nvc5hTpOZ-fQH5SAJGgYFQ.png)
For p∈ℝ, p≥1, the p-norm is a norm on suitable real vector spaces given by the pth root of the sum (or integral) of the pth-powers of the absolute values of the vector components.
对于p∈ℝ,p≥1, p-范数是在适当的实矢量空间上的范数,该实数空间由矢量分量的绝对值的pth幂之和(或积分)的pth根给出。
Using the following code Lᵖ Norm can be implemented-
使用以下代码LᵖNorm可以实现-
# Import Numpy package and the norm function
import numpy as np
from numpy.linalg import norm
# Define a vector
v = np.array([2,3,1,0])
# Take the q-norm which p=2
p = 2
v_norm = norm(v, ord=p)
# Print values
print('The vector: ', v)
print('The vector norm: ', v_norm)
The output will look like this-
输出看起来像这样-
The vector: [2 3 1 0]The vector norm: 3.7416573867739413
L¹范数 (L¹ Norm)
![Image for post](https://miro.medium.com/max/9999/1*i5hIkl98I53J_64qwcoPUQ.png)
If p=1, we simply have the sum of the absolute values. It is what we have used intuitively at the beginning of this tutorial:
如果p = 1,我们就可以得到绝对值的总和。 这是我们在本教程开始时直观使用的内容:
欧几里德范数(L²范数) (The Euclidean Norm(L² norm))
![Image for post](https://miro.medium.com/max/9999/1*_PG5RnCK1Tx4i2ynj7xxig.png)
The L² norm is calculated as the square root of the sum of the squared vector values.theL¹ norm is more robust than the L² norm. This means that the L² norm is more sensible to outliers since significant error values will give enormous squared error values.
L²范数被计算为矢量值平方和的平方根。L¹范数比L²范数更健壮。 这意味着L²范数对异常值更敏感,因为显着的误差值将给出巨大的平方误差值。
最大规范 (The max norm)
![Image for post](https://miro.medium.com/max/9999/1*Ud-YnHyACZX030ETzr-8Qg.png)
L∞ norm corresponds to the absolute value of the greatest element the vector.
大号 ∞范数对应于最大元素的向量的绝对值。
This is the python code of Max Normal-
这是Max Normal的python代码-
# max norm of a vectorfrom numpy import inffrom numpy import arrayfrom numpy.linalg import normv = array([1, 2, 3])print(v)maxnorm = norm(v, inf)print(maxnorm)
Running this code you should get the following output-
运行此代码,您应该获得以下输出:
[1, 2, 3]
3.00
Frobenius范数 (The Frobenius Norm)
![Image for post](https://miro.medium.com/max/9999/1*aAqkmY5tPvFlJ8T3hw3PcQ.png)
This is equivalent to take the L² norm of the matrix after flattening. L² norm is for vectors while Frobenius is for matrices.
这等效于在展平后采用矩阵的L²范数。 L²范数用于矢量,而Frobenius则用于矩阵。
max norm of a vectorfrom numpy import inffrom numpy import arrayfrom numpy.linalg import normv = array([1, 2, 3])print(v)np.linalg.norm(v)
you should get the following output-
您应该获得以下输出-
8.3666002653407556
谢谢! (Thanks!)
That’s all for today.And don’t forget to share your thoughts with me.
今天就这些了,别忘了与我分享您的想法。
翻译自: https://medium.com/swlh/machine-learning-basics-the-norms-3429ddc66d7c
机器学习小数需要规范化吗