权重和偏差在神经网络中起什么作用?

介绍 (Introduction)

We all know that an Artificial Neuron is a basic building block of the neural network. Before we get into the topic, “what is the role of weights and bias in a Neural Network “, let us understand the skeleton of this Artificial Neuron.

我们都知道,一个人工神经是神经网络的基本构建块。 在进入主题“神经网络中的权重和偏见的作用”之前,让我们了解这种人工神经元的骨架。

image by the Author 图片由作者

基本的人工神经元的组成: (Components of the basic Artificial Neuron:)

  1. Inputs: Inputs are the set of values for which we need to predict the output value. They can be viewed as features or attributes in a dataset.

    输入 :输入是我们需要为其预测输出值的一组值。 可以将它们视为数据集中的要素或属性。

  2. Weights: weights are the real values that are associated with each feature which tells the importance of that feature in predicting the final value. (we will know more about in this article)

    权重:权重是与每个要素关联的实际值,表明了该要素在预测最终值中的重要性。 (我们将在本文中了解更多信息)

  3. Bias: Bias is used for shifting the activation function towards left or right, it can be referred to as a y-intercept in the line equation. (we will know more about this in this article)

    偏差:偏差用于将激活函数向左或向右移动,在线性方程式中可以称为y截距。 (我们将在本文中对此有更多了解)

  4. Summation Function: The work of the summation function is to bind the weights and inputs together and find their sum.

    求和函数:求和函数的作用是将权重和输入绑定在一起,以求和。

  5. Activation Function: It is used to introduce non-linearity in the model.

    激活函数:用于在模型中引入非线性。

如果没有重量怎么办? (What if there are no weights?)

We will come to know one’s importance only during its absence

只有在缺席的情况下,我们才会知道自己的重要性

As the statement speaks, let us see what if there are no weights involved in a neuron, for simplicity let us consider there are only two features in the dataset, ie input vector X ϵ [ x₁ x₂ ], and our model task it to perform binary classification.

正如该声明所言,让我们看看如果神经元中没有权重,为简单起见,让我们考虑数据集中只有两个特征,即输入向量X ϵ [x₁x²],以及我们要执行的模型任务二进制分类。

image by the Author 图片由作者

The summation function g(x) sums up all the inputs and adds bias to it.

求和函数g(x)对所有输入求和,并对它加偏置。

and the role of the activation function is to allocate the data points to one of the classes.

激活功能的作用是将数据点分配给这些类之一。

If we compare the model expression with the equation of a line:

如果我们将模型表达式与直线方程进行比较:

we can see that the slope(m) of the equation x₂ = -x₁ + b is fixed that is -1, and it will not change in any case for any dataset, that’s the problem of not having weights in our model, we are not able to draw a scalable line that separates two classes.

我们可以看到方程x2 =-x₁+ b的斜率(m)固定为-1,并且对于任何数据集在任何情况下都不会改变,这就是模型中没有权重的问题,无法画出一条将两个类分开的可缩放线

让我们以一个例子来理解... (Let us understand with an example…)

Consider this sample dataset for illustration, which contains two independent features [x₁ and x₂] and one dependent feature y, our task is to classify a given data point to one of the classes that belong to feature y.

考虑该示例数据集以进行说明,该数据集包含两个独立的特征[x 1和x 2]和一个相关的特征y,我们的任务是将给定的数据点分类为属于特征y的一类。

image by the author 作者形象

From the data, we infer that

根据数据,我们推断

Now if we try to fit the line equation ( x₂ = -x₁ + b) for the different values of b we will get this plot…

现在,如果我们尝试将线性方程式(x²=-x₁+ b)拟合为不同的b值,我们将得到此图…

image by the author 作者形象

If we consider the value of b is 0, the line equation looks like (x₂ = -x₁ + 0), it is represented as the orange line in the above plot.

如果我们认为b的值为0,则线方程看起来像( x 2 =-x₁+ 0 ),在上面的图中它表示为橙色 线

If we consider the value of b is 1, the line equation looks like (x₂ = -x₁ + 1), it is represented as the blue line in the above plot.

如果我们认为b的值为1, 线方程看起来像( x 2 =-x₁+ 1 ),在上图中以 线表示。

If we consider the value of b is 2, the line equation looks like(x₂ = -x₁ + 2), it is represented as the green line in the above plot.

如果我们认为b的值为2,则线方程看起来像( x 2 =-x₁+ 2 ),在上面的图中它表示为绿线

If we go on changing the value of b, we will only end up with parallel lines, but there will not be any change in the orientation or slope of the line, so this equation with a fixed slope will not be efficient for every dataset, that is the reason we require weights to change the orientation of the line.

如果我们继续更改b的值,则最终只会得到平行线,但线的方向或斜率不会发生任何变化,因此,具有固定斜率的该方程将不适用于每个数据集,这就是为什么我们需要权重来更改线的方向的原因。

When we assign weights to each input then the equation looks like…

当我们为每个输入分配权重时,方程看起来就像…

the line that better fits the above dataset is: x₁ = 0

最适合上述数据集的行是: x₁ = 0

看一下涉及权重的情节... (Take a look at the plot when the weights are involved…)

when w2 = 0, w1 = 1, b = 0, the equation fits the data set in a best way.

当w2 = 0,w1 = 1,b = 0时,该方程以最佳方式拟合数据集。

image by the author 作者形象

From the plot, we can observe that the slope of the line, which is the orientation of the line has been changed with the introduction of weights in the equation.

从图中可以看出,线的斜率(即线的方向)已随着方程中引入权重而发生了变化。

神经元中的权重传达给我们什么? (What do the weights in a Neuron convey to us?)

1.功能的重要性 (1. Importance of the feature)

Weights associated with each feature, convey the importance of that feature in predicting the output value. Features with weights that are close to zero said to have lesser importance in the prediction process compared to the features with weights having a larger value.

与每个功能关联的权重传达了该功能在预测输出值中的重要性。 与权重具有较大值的特征相比,权重接近零的特征在预测过程中的重要性较低。

2.告诉数据集中的特定特征与目标值之间的关系。 (2. Tells the relationship between a particular feature in the dataset and the target value.)

let us consider an example of finding the likelihood of buying a car, with the dataset containing two input features like

让我们考虑一个发现购买汽车可能性的示例,该数据集包含两个输入特征,例如

  1. Car price

    车价
  2. Car Popularity

    汽车人气

and let us suppose that people often tend to buy a car within their budget and the most popular one among many.

让我们假设人们通常倾向于在预算范围内购买汽车,而这是其中最受欢迎的一种。

the equation of line looks like…

线的方程看起来像…

if the price of the car increases, then the expression value also increases, that means “we are more likely to buy that car”, but we don’t want that to happen, so we have to compensate it with a negative valued weight (w₁) so that their product becomes negative and the value of expression decreases, that implies we are not interested in buying that car, in this way wights help us.

如果汽车的价格上涨了,那么表达的价值也会增加,这意味着“我们更有可能购买那辆汽车”,但是我们不希望这种情况发生,因此我们必须用负值的重量来补偿它( w₁),以使它们的乘积变为负数,表达的值减小,这意味着我们对购买那辆车不感兴趣,这样权重就可以帮助我们。

so if the weight associated with a feature is positive it implies that there is a direct relationship between that feature and the target value, and if the weight associated with the feature is negative it implies that there is an inverse relationship between the feature and the target value.

因此,如果与某个特征相关联的权重为正,则表示该特征与目标值之间存在直接关系;如果与该特征相关联的权重为负,则意味着在特征与目标之间存在逆关系。值。

摘要 (Summary)

  • Weights play an important role in changing the orientation or slope of the line that separates two or more classes of data points.

    权重在更改分隔两个或更多类数据点的线的方向或斜率方面起着重要作用。
  • Weights tell the importance of a feature in predicting the target value.

    权重表明功能在预测目标值中的重要性。
  • Weights tell the relationship between a feature and a target value

    权重说明要素与目标值之间的关系

在神经元中使用偏差? (Use of Bias in the Neuron?)

Bias is used for shifting the activation function towards the left of right, did not get this statement? don’t worry let’s understand it with a visual experience …

偏差用于将激活功能向右移,没有得到这个陈述? 别担心,让我们以视觉体验来理解它……

let us consider a sigmoid activation function to demonstrate the use of bias, we can represent the sigmoid activation function with the mathematical expression as

让我们考虑使用S形激活函数来演示偏倚的使用,我们可以用以下数学表达式表示S形激活函数:

replacing x with the equation of a line

用直线方程式替换x

1.让我们改变w的不同值并将b值固定为0 (1. Let us vary different values of w and fix the b value to 0)

image by the author 作者形象

when the value of b =0 and

当b的值= 0且

w = 0.3 — the blue line in the plot

w = 0.3-图中的蓝线

w= 0.5 — the red line in the plot

w = 0.5-图中的红线

w = 0.7 — the green line in the plot

w = 0.7-图中的绿线

Even while giving different values of w, we could not shift the center of the activation function, in this case, the sigmoid function.

即使给出不同的w值,我们也无法移动激活函数(在此情况下为S型函数)的中心。

Changing the value of w only changes the steepness of the curve, but there is no way we cans shift the curve towards left or right, the only way to shift the curve towards left or right is by changing the value of bias(b).

改变w的值只会改变曲线的陡度,但是我们无法将曲线向左或向右移动,将曲线向左或向右移动的唯一方法是改变bias(b)的值。

2.让我们改变b的不同值并将w值固定为0.5 (2. Let us vary different values of b and fix w value to 0.5)

image by the author 作者形象

when the value of w=0.5 and

当w = 0.5且

b = -1 — the red line in the plot

b = -1-图中的红线

b= -5 — the green line in the plot

b = -5-图中的绿线

b = 1 — the blue line in the plot

b = 1-图中的蓝线

b = 5 — the yellow line in the plot

b = 5-图中的黄线

look at the plot, changing the value of b changes the position of the curve, hence bias is used for shifting the activation function towards left or right.

看图,改变b的值会改变曲线的位置,因此使用偏置将激活函数向左或向右移动。

为什么我们需要将激活功能向右移? (Why do we need to shift the activation function towards the left of right?)

Let us understand the working of sigmoid first…

首先让我们了解乙状结肠的工作...

image by the author 作者形象

The equation of the curve is

曲线的等式为

From the plot, we infer that all the values towards the right of 0 are mapped to 1 and all the values towards the left of 0 are mapped to 0.

根据该图,我们推断出0右边的所有值都映射为1而0左边的所有值都映射为0

let us take if x = -1 then the corresponding y value is around 0.1, and we round it to 0, now let us take x= 5 then the corresponding y value is around 1, and we round it to 1.

让我们假设x = -1,则对应的y值约为0.1,然后将其舍入为0,现在让我们接受x = 5,则对应的y值约为1,然后将其舍入为1。

如果我们希望当x <5时y的值为0,该怎么办? (what if we want y value to be 0 when x<5?)

The answer is you need to shift the curve towards the right, ie

答案是您需要将曲线向右移动,即

image by the author 作者形象

The equation of the curve is

曲线的等式为

from the plot, we can infer that all the point to the left of the point x=5, seems to have y value less than 0.5, which when rounded ends up with value 0. Hence we achieved our goal by shifting the curve towards shift, and bias is responsible for shifting the curve towards the right, that’s the use of bias in an Artificial Neuron.

从图中可以推断出,点x = 5左侧的所有点的y值似乎都小于0.5,四舍五入时的y值为0。因此,我们通过将曲线向shift方向移动来实现了目标。 ,并且偏向负责将曲线向右移动,这就是在人工神经元中使用偏向的原因。

结论 (Conclusion)

I hope this article cleared all your doubts about why we need weights and bias in the Artificial Neuron.

我希望本文能消除您对为什么我们需要人工神经元的重量和偏见的所有疑问。

感谢您的阅读祝你有美好的一天 (Thanks for reading Have a nice day)

翻译自: https://towardsdatascience.com/whats-the-role-of-weights-and-bias-in-a-neural-network-4cf7e9888a0f

你可能感兴趣的:(神经网络,深度学习,python,算法)