-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,74 @@ | ||
|
||
<style> | ||
.image.fit{ | ||
all: unset; | ||
display: inline-block; | ||
margin-bottom: -5px; | ||
} | ||
</style> | ||
|
||
# How do you derive the Gradient Descent rule for Linear Regression and Adaline? | ||
|
||
Linear Regression and Adaptive Linear Neurons (Adalines) are closely related to each other. In fact, the Adaline algorithm is a identical to linear regression except for a threshold function  that converts the continuous output into a categorical class label | ||
Linear Regression and Adaptive Linear Neurons (Adalines) are closely related to each other. In fact, the Adaline algorithm is a identical to linear regression except for a threshold function  that converts the continuous output into a categorical class label | ||
|
||
 | ||
 | ||
|
||
where $z$ is the net input, which is computed as the sum of the input features **x** multiplied by the model weights **w**: | ||
|
||
 | ||
 | ||
|
||
(Note that  refers to the bias unit so that .) | ||
(Note that  refers to the bias unit so that .) | ||
|
||
In the case of linear regression and Adaline, the activation function  is simply the identity function so that . | ||
In the case of linear regression and Adaline, the activation function  is simply the identity function so that . | ||
|
||
 | ||
 | ||
|
||
Now, in order to learn the optimal model weights **w**, we need to define a cost function that we can optimize. Here, our cost function  is the sum of squared errors (SSE), which we multiply by  to make the derivation easier: | ||
Now, in order to learn the optimal model weights **w**, we need to define a cost function that we can optimize. Here, our cost function  is the sum of squared errors (SSE), which we multiply by  to make the derivation easier: | ||
|
||
 | ||
 | ||
|
||
where  is the label or target label of the *i*th training point . | ||
where  is the label or target label of the *i*th training point . | ||
|
||
(Note that the SSE cost function is convex and therefore differentiable.) | ||
|
||
In simple words, we can summarize the gradient descent learning as follows: | ||
|
||
1. Initialize the weights to 0 or small random numbers. | ||
2. For *k* epochs (passes over the training set) | ||
A. For each training sample  | ||
a. Compute the predicted output value  | ||
b. Compare  to the actual output  and Compute the "weight update" value | ||
c. Update the "weight update" value | ||
B. Update the weight coefficients by the accumulated "weight update" values | ||
3. For each training sample  | ||
- Compute the predicted output value  | ||
- Compare  to the actual output  and Compute the "weight update" value | ||
- Update the "weight update" value | ||
4. Update the weight coefficients by the accumulated "weight update" values | ||
|
||
Which we can translate into a more mathematical notation: | ||
|
||
1. Initialize the weights to 0 or small random numbers. | ||
2. For *k* epochs | ||
3. For each training sample  | ||
1.  | ||
2.  (where *η* is the learning rate); | ||
3.  (*t* is the time step) | ||
|
||
3.  | ||
3. For each training sample  | ||
-  | ||
-  (where *η* is the learning rate); | ||
-  | ||
3.  | ||
|
||
Performing this global weight update | ||
|
||
, | ||
, | ||
|
||
can be understood as "updating the model weights by taking an opposite step towards the cost gradient scaled by the learning rate *η*" | ||
|
||
 | ||
 | ||
|
||
where the partial derivative with respect to each  can be written as | ||
where the partial derivative with respect to each  can be written as | ||
|
||
 | ||
 | ||
|
||
|
||
|
||
To summarize: in order to use gradient descent to learn the model coefficients, we simply update the weights **w** by taking a step into the opposite direction of the gradient for each pass over the training set -- that's basically it. But how do we get to the equation | ||
|
||
 | ||
 | ||
|
||
Let's walk through the derivation step by step. | ||
|
||
 | ||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.