Given a dataset such as and are continuous, The goal of "Linear Regression" is to find the best line that fits this data.
In other words, we want to create the model:
where is the number of dimensions of the variable .
In this article we will see how to solve this problem in three scenarios:
- When X is one dimensional i.e. .
- When X is multi-dimensional i.e. .
- Using gradient descent.
is one dimensional (Ordinary Least Square)
The model that we want to create is of shape:
Remember that the goal of linear regression is to find the line that best fits the data. In other words, we need to minimize the distance between the data points and the line.
In order to find the minimum, we need to solve the following equations:
We start by developing the first equation:
We substitute in the second equation:
We substitute back in :
is multi-dimensional (Ordinary Least Square)
In this case, is no longer a real number, but instead it's a vector of size :
So, the model is written as follow:
or, it can be written in a matrix format:
- is of shape .
- is of shape .
- is of shape : this is the parameters vector .
Similarly to the first case, we aim to minimize the following quantity:
Again let's put:
Since we want to minimize with respect to , then we can ignore the first term "" because it's independent of and let's solve the following equation:
Using gradient descent
Here is the formulation of the gradient descent algorithm:
Now all we have to do is to apply it on the two parameters and (in the case of a one variable ):
and we know that:
- What is the formula of the optimal parameters vector in the case of multidimensional linear regression:
- Why do we put the derivative to 0?
- To find the extremum. "correct"
- To minimize the derivative.
- To only keep the real part of the derivative.
- What is the objective of linear regression ?
- To find the line that passes by all the points.
- To find the line that best describes the data."correct"
- To find the line that best separates the data.