Linear Regression

Navjot Singh
Analytics Vidhya
Published in
3 min readJun 2, 2020

--

Linear Regression is one of the most simple Machine learning algorithm that comes under Supervised Learning technique and used for solving regression problems.

It is used for predicting the continuous dependent variable with the help of independent variables.The goal of the Linear regression is to find the best fit line that can accurately predict the output for the continuous dependent variable.

By finding the best fit line, algorithm establish the relationship between dependent variable and independent variable.

The output for Linear regression should only be the continuous values such as price, age, salary, etc.

Linear Regression is generally classified into two types:

  • Simple Linear Regression.
  • Multiple Linear Regression.

Simple Linear Regression

In simple Linear Regression basically there is one dependent and one independent variables and is defined by the formula:

b0 = represents the intercept

b1 = represents the coefficient

x = represents the independent variable

y = represents the output or the dependent variable

It is a regression model with a single explanatory variable.

A portion of the estimation process for the y-intercept is based on the exclusion of relevant variables from the regression model.

Multiple linear regression

For a Multiple linear regression when we have more than one input (x), the line is called a plane or hyper plane. The representation, therefore, is the form of the equation.

Least Squares Regression Line

least squares regression is a way to find the line of best fit for a set of data. It does this by creating a model that minimizes the sum of the squared vertical distances (residuals).

The distances are squared to avoid the problem of distances with a negative sign. Then the problem just becomes figuring out where you should place the line so that the distances from the points to the line are minimized.

Gradient Descent

Gradient Descent is the process of minimizing a function by following the gradients of the cost function.To find a local minimum of a function using gradient descent, we take steps proportional to the negative of the gradient of the function at the current point.

This involves knowing the form of the cost as well as the derivative so that from a given point you know the gradient and can move in that direction.

Python Implementation

Dataset: Salary

Here is the link for python implementation of linear regression on salary dataset :

https://github.com/InternityFoundation/MachineLearning_Navu4/tree/master/Day%206%20:%20Linear%20Regression

Here’s the Jupyter notebook for the python implementation of Linear regression Mathematical way.

Link :https://github.com/InternityFoundation/MachineLearning_Navu4/blob/master/Day%206%20:%20Linear%20Regression/Linear_regression(mathematical_way).ipynb

--

--

Navjot Singh
Analytics Vidhya

Machine learning enthusiast interested in making data actionable.