• Linear regression is an approach of modeling the relationship between a dependent variable and
one or more independent variables.
• It finds the line of best fit through your data by searching for the value of the regression
coefficient(s) that minimizes the total error of the model.
• Let X be the independent variable and Y be the dependent variable. Linear relationship between
these two variables is defined as follows:
Our goal is to find (m, c), where c is Intercept (where the line crosses y-axis), m is Slope of the line
We will use the Mean Squared Error function to calculate the loss
Linear Regression Using Gradient
Descent
Algorithm
Input: Training data (X, Y) L learning rate
Ouput: m, c
1. Initially assign m=0, c=0 and L be the learning rate.
2. Calculate the partial derivative of the loss function with respect to m, and plug in the current values of x, y, m and c in it to obtain the derivative value D. D is the value of the partial derivative with respect ₘ to m.
Similarly, Dc is the partial derivative with respect to c,
3. Update the current value of m and c using the following equation
4. Repeat steps 2 and 3 until our loss function is a very small value or ideally 0 (which means 0 error or 100% accuracy).
5. The final value of m and c will be the optimum values for the best-fitted line and we can predict the value of Y for any given X.