Implementation of Simple Linear Regression using Formulae
Photo by Ridham Nagralawala on Unsplash

Probably the first algorithm you come to know when you start exploring the world of machine learning is linear regression!

It is a simple yet powerful supervised machine learning algorithm. It tries to find the best fitted straight line from the points. In other words, this algorithm assumes output variable can be calculated from a linear combination of the input variables.

Fig 1. Visual representation of a linear data set

The above figure represents a simple Demand vs. Product Price scatter plot. After seeing this plot, we can say that there is a reasonably linear correlation between both the variables. As demand of the product increases, product price also increases. In linear regression, we try to find the best fitted straight line through such points which results in minimum prediction error.

There are 2 types of linear regression:

1. Simple/ Univariate linear regression

2. Multiple/ Multivariate linear regression.

The number of independent/input variables defines the type of algorithm.

If there is only one variable on which output variable depends, it is called simple/ univariate linear regression. For example, let’s assume the quality of wine only depends upon the pH value irrespective of other attributes. In this blog, we will understand simple linear regression using the formulae which we are going to explore further.

Quality of wine = a (pH) + z

Here, z is a constant also known as intercept and a is the coefficient added to the variable.

What if there are more attributes which affects the quality of wine? Let’s assume, there are many attributes like pH value, citric acid, residual sugar, alcohol etc. which affect the quality of wine. In multivariate linear regression there are at least 2 variables which affect the output variable.

Quality of wine = a (citric acid) + b (residual sugar) + c (pH) + d (alcohol) + z

Here, a, b, c and d are the coefficients added to their respective variables along with an intercept i.e. z.
['Adesh Dalvi']
['Machine Learning', 'Linear Regression', 'Python', 'Algorithms', 'Data Science']