Linear Regression Algorithm. Explained...

Shashank Shanu

a year ago

A step by step explanation of Linear Regression Algorithm.
Linear Regression Algorithm | Insideaiml
Linear Regression Algorithm | Insideaiml

Hello Folks,
Hope you are well and staying safe at your place. As we all know how this COVID-19 pandemic came and doesn't want to go from our life.
But as the whole world is fighting to get rid of this pandemic. I thought why can't I share some things which I know so that many people may get benefits from it. 
So Let's start without wasting much time.
Before directly going deep into Linear regression algorithm.
Let us first understand

What is Regression?

Regression is a statistical technique that shows an algebraic relationship between two or more variables.
Based on this algebraic relationship (rather than a function), one can estimate the value of a variable (dependent variables), given the values of the other variables (independent variables).
Usually, correlation is used to check whether there is any relationship between the two variables. If any relationship found, regression is used to find a degree of relationships that can be then used for prediction.
Some of the examples are:
1)    Predict rainfall in cm for a month.
2)    Predict stock price for the next day.
Now as you got some idea about what is regression? Let’s move forward and see what are the types of regressions?
Types of Regressions
  • Linear regression
  • Logistic regression
  • Polynomial regression
  • Stepwise regression
  • Stepwise regression
  • Ridge regression
  • Lasso regression
  • ElasticNet regression
In this article, I will explain to you about Linear Regression only and later I will try to take you through the other types of regressions.

What is a Linear Regression?

Linear Regression is one of the most fundamental and used algorithms in the Machine Learning world which comes under supervised learning. Basically it performs a regression task.
Regression models predict a dependent (target) value based on independent variables. It is mostly used for finding out the relationship between variables and forecasting.
Different regression models differ based on – the kind of relationship between the dependent and independent variables, they are considering and the number of independent variables being used.    
Linear Regression Plot | Insideaiml
Linear Regression Plot | Insideaiml
Linear regression performs the task to predict a dependent variable value (y) based on a given independent variable (x). So, this regression technique is used to find out a linear relationship between x (independent variables) and y (dependent variables). Hence, it is known as Linear Regression.
Let's suppose, in the above figure above X (in
dependent variables) is the work experience and Y (dependent variables) is the salary of a person. The regression line is the best fit line for our model.
Linear Regression may further be divided into
1)    Simple Linear Regression/ Univariate Linear regression
2)    Multivariate Linear Regression
Simple Linear Regression/ Univariate Linear regression
When we try to find out a relationship between a dependent variable (Y) and one independent (X) then it is known as Simple Linear Regression/ Univariate Linear regression.
The mathematical equation can be given as:
                                                             Y = β0 + β1*x
  • Y is the response or the target variable
  • x is the independent feature
  • β1 is the coefficient of x
  • β0 is the intercept
β0 and β1 are the model coefficients (or weights). To create a model, we must "learn" the values of these coefficients. And once we have the value of these coefficients, we can use the model to predict the target variable such as Sales!
NOTE: The main aim of the regression is to obtain a line that best fits the data. The best fit line is the one for which total prediction error (all data points) are as small as possible. Error is the distance between the points to the regression line.
Let us consider Real-time example
Let’s suppose we have a dataset which contains information about the relationship between ‘a number of hours studied’ and ‘marks obtained’. Many students have been observed and their hours of study and grade are recorded. This will be our training data. The goal is to design a model that can predict marks if given the number of hours studied. Using the training data, a regression line is obtained which will give the minimum error. This linear equation is then used for any new data. That is, if we give the number of hours studied by a student as an input, our model should predict their mark with minimum error.

Submit Review